Today, we will show you example to Create MySQL Database using PHP Script. Here we are using mysqli_query() function to create database.
NOTE : mysqli_query() function Performs a query operation on the database.
mysqli_connect() function is not available form PHP 7
PHP MySQLi Create Database Example
Lets see the simple example to create MySQL database using mysqli_query() function.<?php $host = 'localhost'; //set the hostname $user = 'set mysql DB Username'; // set mysql username $pass = 'set mysql DB Password'; // set mysql password //connecting to mysql database $conn = mysqli_connect($host, $user, $pass); if(! $conn ) { die('Could not connect: ' . mysqli_connect_error()); } echo 'Connected successfully to mysql database<br/>'; // perform mysql query to create database. $sql = 'CREATE Database Demodbname'; if(mysqli_query( $conn,$sql)){ echo "Database mydb created successfully."; }else{ echo "Sorry, database creation failed ".mysqli_error($conn); } mysqli_close($conn); ?>Output:
-----------------------
Connected successfully to mysql database.
Database mydb created successfully.
No comments:
Post a Comment