Pages

Creating a Database from within PHP

Creating a database from the PHP code on runtime is very simple by using a combination of Structured Query Language and the PHP mysql_query() function.

CREATE DATABASE databaseName,

mysql_query("CREATE DATABASE databaseName");

for more clarification checkout the following complete example:

<?php
$hostname = "localhost";
$username = "zohaib";
$password = "12345";
$connection = mysql_connect($hostname,$username,$password);
if (!$connection)
{
 echo "error :".mysql_error();
}
if (!mysql_query("CREATE DATABASE myNewDatabase"))
{
echo "Not done: ".mysql_error();
}
else
{
echo "New database created.";
}
?>


This will create the new database, After the creation of database you can also create table in this database in the similar way.

 

0 comments:

Post a Comment