PHP Create Database MySQL
Advertisements
PHP Create Database MySQL
Using below syntax we can create database in MYSQL.
Syntax
CREATE Database database_name;
connect-db.php
Connect to database
<?php $server = 'localhost'; $user = 'user_name'; $pass = 'password'; $db = 'database_name'; // Connect to Database $connection = mysql_connect($server, $user, $pass) or die("Could not connect to server ... \n" . mysql_error ()); // select database mysql_select_db($db) or die("Could not connect to database ... \n" . mysql_error ()); ?>
create-database.php
Create Database in database
<?php include 'connect-db.php'; $sql = 'CREATE Database mydb'; $result mysqli_query($sql, $connection); if($result)) { echo "Database mydb created successfully......"; } else { echo "Sorry, database creation failed ".mysqli_error($conn); } mysqli_close($connection); ?>
Output
Database mydb created successfully......
Google Advertisment