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 / lt

<?php
$link = mysql_connect('localhost', 'mysql_user',
'mysql_password');
if (!$link) {
die('Could not connect: ' . mysql_error());
}

$sql = 'CREATE DATABASE my_db';
if (mysql_query($sql, $link)) {
echo "Database my_db created successfully\n";
} else {
echo 'Error creating database: ' . mysql_error() . "\n";
}
?>

Is This Answer Correct ?    5 Yes 0 No

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

Answer / ram

mysql_create_db -- Create a MySQL database
syntax: bool mysql_create_db ( string database_name [,
resource link_identifier])
<?php
$con=mysql_connect("localhost","root","");

if(!$con)
{
die("could not connect:".mysql_error());
}
$dbname='CREATE DATABASE prasad';

if(mysql_query($dbname,$con))
{
echo "Database Created successfully";
}
else
{
echo 'error message:' .mysql_error();
}
?>

Is This Answer Correct ?    2 Yes 0 No

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

Answer / sunil kumar

It`s simple than above

<?php
mysql_connect("localhost","root","");//connect to host
$sql_create_db="create database my_db";
if(mysql_query($sql_create_db))
echo"Database is created";
else
echo"Error in creating Database".mysql_error();

?>

Is This Answer Correct ?    2 Yes 0 No

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

Answer / rahul

by using phpmyadmin

Is This Answer Correct ?    2 Yes 4 No

Post New Answer

More PHP Interview Questions

what is the best function that can be used to connect to mysql database and in what cases that we can use below functions ? 1. mysql_connect() 2. mysql_pconnect() please give your answer with all pros and cons

1 Answers  


What are sql functions?

0 Answers  


Explain me what is the difference between $_files['userfile']['name'] and $_files['userfile']['tmp_name']?

0 Answers  


What is indexing how many types?

3 Answers   DLF, Infosys, Net Solution, Vcare,


Which function is used to strip whitespace?

0 Answers  






How can we change the value of a constant?

0 Answers  


What are the different functions in sorting an array?

1 Answers  


Apart from mail() function to send emails,is there any other functions in PHP to send emails?

4 Answers  


List some string function name in php?

0 Answers  


What is difference between ksort() and usort() functions.

0 Answers  


What is the difference between PHP,ASP and JSP?

3 Answers   T3 Softwares,


How to strip whitespace (or other characters) from the beginning and end of a string?

0 Answers  


Categories