PHP Create Database MySQL

Advertisements

Get data From Html Form using PHP Create Table Mysql PHP

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......

Get data From Html Form using PHP Create Table Mysql PHP

Google Advertisment

Buy This Ad Space @$20 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 9999595223

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

For Projects 9999595223

Google Advertisements


Buy Websites 9999595223

Buy College Projects with Documentation Contact on whatsapp 9999595223. Contact on: hitesh.xc@gmail.com or 9999595223 Try this Keyword C++ Programs

Advertisements