How can we create a database using PHP and mysql?

Answers were Sorted based on User's Feedback



How can we create a database using PHP and mysql?..

Answer / tina

1.mysql_connect('ip address/localhost','username for
mysql','password');
i.e
$con=mysql_connect('localhost','root','sdsd');
here,$con is a user defined variable.

2.$quer=CREATE DATABASE sampdb;
mysql_query($quer,$con);

Here,$quer is also user defined variable.

if(mysql_query($quer,$con)
{
echo("DATABASE WAS BEEN CREATED");
}
else
echo("NOT CREATED");

Is This Answer Correct ?    6 Yes 0 No

How can we create a database using PHP and mysql?..

Answer / vivek mohan singh

$dbhost = "localhost"; // database hostname
$dbuser = "root"; // database username
$dbpassword = ""; // database password
$dbname = ""; // database name

//database connection
$link=mysql_connect($dbhost,$dbuser,$dbpassword) or die ('I
cannot connect to the database because: ' . mysql_error());
mysql_select_db($dbname ,$link);

Is This Answer Correct ?    6 Yes 5 No

How can we create a database using PHP and mysql?..

Answer / b.chandrasekaran

using
mysql_db_create("databasename");

we can create new database in php.

Is This Answer Correct ?    1 Yes 1 No

Post New Answer

More PHP Interview Questions

Which function can be used to exit from the script after displaying the error message?

0 Answers  


How To Get the Uploaded File Information in the Receiving Script?

0 Answers  


What is print_r?

0 Answers  


If i make my selection in State Dropdown list, i would the City and ZipCode dropdown list to be automatically reupdated based on the State i select.(This to avoid the user select a City or Zipcode that does not correspond to the State previously selected.)

2 Answers   CMC, PHP,


Do you know what is the use of the function 'imagetypes()'?

0 Answers  






What is needed to be able to use image function?

0 Answers  


What are helpers in php?

0 Answers  


Is not null mysql?

0 Answers  


What is the use of limit in mysql?

0 Answers  


What is parent __construct ();?

0 Answers  


What is the function file_get_contents() usefull for?

0 Answers  


Why super () is used in java?

0 Answers  


Categories