0

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

2
  • Syntax mistakes: $SQLString = "CREATE DATABASE `employee`"; // was "CREATE DATABASE $employee"; Commented Mar 22, 2014 at 16:23
  • 1
    You should not be using mysql_* functions as the extension has been deprecated. Use PDO or mysqli instead! Commented Mar 22, 2014 at 16:24

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.