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
What is the difference between echo, print and printf()?
What are the encryption functions in php?
What is the use of magic function in php?
What is the difference between php4 and php5?
Can php replace javascript?
Where are the persistent cookies stored on your computer?
What is the correct and the most two common way to start and finish a php block of code?
Which operator is used to combine string values in php?
How to concatenate two strings together in php?
Why php language is used?
What is a php 5?
Can you use php and javascript together?
Define anonymous classes in php7?
What is constructors and destructors?
What is advanced php programming?