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 |
Explain what are psrs?
What is difference between Method overriding and overloading in PHP?
What are the security measures we have to take for our site not to hack by others.
3 Answers Infosys, Torque Infotech,
What are php expressions?
How can we submit a form without a submit button? What is the use of obj_star?
2 Answers Rushmore Consultancy,
What are the different methods of passing data or information between two calls of a web page? What are the advantages/disadvantages of these methods?
Explain Creating and Naming an Array?
How can we know the total number of elements of Array?
How can we display information of a variable and readable by a human with php?
How cookies are transported from browsers to servers?
What are escaping characters? Explain with an example?
what is the difference between mysql_fetch_array() and mysql_fetch_row()?