How can we create a database using PHP and mysql?

Answers were Sorted based on User's Feedback



How can we create a database using PHP and mysql?..

Answer / tina

1.mysql_connect('ip address/localhost','username for
mysql','password');
i.e
$con=mysql_connect('localhost','root','sdsd');
here,$con is a user defined variable.

2.$quer=CREATE DATABASE sampdb;
mysql_query($quer,$con);

Here,$quer is also user defined variable.

if(mysql_query($quer,$con)
{
echo("DATABASE WAS BEEN CREATED");
}
else
echo("NOT CREATED");

Is This Answer Correct ?    6 Yes 0 No

How can we create a database using PHP and mysql?..

Answer / vivek mohan singh

$dbhost = "localhost"; // database hostname
$dbuser = "root"; // database username
$dbpassword = ""; // database password
$dbname = ""; // database name

//database connection
$link=mysql_connect($dbhost,$dbuser,$dbpassword) or die ('I
cannot connect to the database because: ' . mysql_error());
mysql_select_db($dbname ,$link);

Is This Answer Correct ?    6 Yes 5 No

How can we create a database using PHP and mysql?..

Answer / b.chandrasekaran

using
mysql_db_create("databasename");

we can create new database in php.

Is This Answer Correct ?    1 Yes 1 No

Post New Answer

More PHP Interview Questions

Which is incorrect with respect to separating php code and html?

0 Answers  


How can you retrieve data from the mysql database using php?

0 Answers  


How can MYSQL functions be available with PHP?

0 Answers  


What are the functions of string?

0 Answers  


How to get ip address of a server in php?

0 Answers  






What's the difference between accessing a class method via -> and via ::?

0 Answers  


i got 2 year backs in my MCA,i am 28 year guy, presently learning PHP, can i get the job & on facing the interview wht i will answer out for that?? (experience in as a 1.5yr System analyst after graduation)

0 Answers  


Write down the code for saving an uploaded file in PHP.

0 Answers  


What are the four scalar types of php?

0 Answers  


What is the use of get and post method in php?

0 Answers  


how to uploade video in php????

1 Answers  


Can php use gettext?

0 Answers  


Categories