Reputation: 1
I am a very beginner in PHP & mysql. I was searching for the syntax for creating a new database and found the following: (( Assuming I am trying to create "employee" database))
$result= mysql_create_db("employee", $DBconnect);
$SQLString = "CREATE DATABASE $employee";
$QueryResult = @mysql_query($SQLString, $DBconnect);
$sql = 'CREATE DATABASE 'employee';
$createdb=mysql_create_db(employee, $dbconnect);
Can anyone help me to figure the differences between all of those?? PLZ let me know if there is any syntax mistakes!!
Upvotes: 0
Views: 169
Reputation: 225273
You generally shouldn’t be creating databases dynamically. What’s this for?
Anyways, this:
$result = mysql_create_db("employee", $DBconnect);
uses the deprecated mysql_
extension, and it shouldn’t be used. It also creates a database named “employee”.
This:
$SQLString = "CREATE DATABASE $employee";
$QueryResult = @mysql_query($SQLString, $DBconnect);
squashes errors and uses the deprecated mysql_
extension, and it shouldn’t be used. It creates a database with the name of whatever’s in $employee
.
This:
$sql = 'CREATE DATABASE 'employee';
$createdb=mysql_create_db(employee, $dbconnect);
is syntactically invalid, doesn’t use the $sql
variable, uses a deprecated extension, uses $dbconnect
instead of $DBConnect
, and attempts to use the constant employee
and probably fails over to the literal 'employee'
. Shouldn’t be used.
Upvotes: 2