How can we create a database using PHP and mysql?
Answer Posted / 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 |
Post New Answer View All Answers
How to stop the execution of php script?
Can we use php variable in javascript?
Explain me what is the difference between explode() and split() functions?
What are php parameters?
What is the main difference between asp net and php?
I am trying to assign a variable the value of 0123, but it keeps coming up with a different number, what is the problem?
Explain some most commonly use string functions in php?
How to change the principal password?
What are the four scalar types of php?
What is the difference between html and php?
What is the php function that removes the first element of the array and returns it?
Write a program to upload a file in php?
Why do we use in php?
How to pass variables by references?
What is difference between rest and http?