How can we create a database using PHP and mysql?
Answers were Sorted based on User's Feedback
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 |
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 |
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 you execute php script from the command line?
Explain the difference between session and cookies in php?
How we can convert dynamic url into static url? plz provide code.
Explain about the $_GET variable of PHP?
What is an example of a variable?
how to send mail in php but mail should be send in inbox not in spam.....:(
What does odbc do in context with php?
Which is not a file-related function in php?
Explain about the data types in PHP?
Tell me how can we automatically escape incoming data?
how to change the div background color on every refresh..guys can u help me out.
What does php mean?