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
Explain Creating and Naming an Array?
What is data structure in php?
Do you know how to delete a file from the system?
How do you destroy a session?
Can you give example for trait in php?
Explain the difference between session and cookies in php?
What is final class and final method in php?
What is the difference between null and empty?
How to add comments in php?
Write down the code for save an uploaded file using php?
what is the use of include_once in php?
Difference between array_combine and array_merge?
How to include a file to a PHP page?
What is overloading and overriding in php?
What exactly is validating and sanitizing?