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

Why are sessions used?

0 Answers  


How does php serialize work?

0 Answers  


How can you compare objects in php?

0 Answers  


What the use of var_dump()?

0 Answers  


What is the function of string in c?

0 Answers  


When viewing an html page in a browser, the browser often keeps this page in its cache. What can be possible advantages/disadvantages of page caching? How can you prevent caching of a certain page (please give several alternate solutions)?

0 Answers  


How to communicate with sockets in php?

1 Answers  


What is the default time in seconds for which session data is considered valid?

0 Answers  


Could we start a variable with number like $4name?

0 Answers  


What is polymorphism in php?

0 Answers  


Hi, My Name is Ajay Jha. What My Question is I am Percuing in Bca. It's My 5th Semester. I Want To Make My Carrear as a web designer that's Why i wants to do Php, Is it right Desision for Me ?

1 Answers  


What are sql functions?

0 Answers  


Categories