How can we connect to a mysql database from a php script?



How can we connect to a mysql database from a php script?..

Answer / Ankit Kumar Rathi

To connect to a MySQL database from a PHP script, you need to use the mysqli extension. Here's an example: <?php $conn = new mysqli("localhost", "username", "password", "database"); if ($conn->connect_error) {n die("Connection failed: " . $conn->connect_error);n}n ?>

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More PHP Interview Questions

What are the different filter functions used to filter a variable?

1 Answers  


i'm b.com graduate and doing MCM- 1year(Master in Computer Management. i'm very interested in PHP? Please tell me some suggetion and the scope of PHP in the market. My E-mail pawan.register@gmail.com Thanks & Regards Pawan.

1 Answers  


How many types of array supported in php?

1 Answers  


How can I retrieve values from one database server and store them in other database server using PHP?

1 Answers  


How to execute an sql query?

1 Answers  


What is the difference between PHP,ASP and JSP?

3 Answers   T3 Softwares,


What is the difference between ereg_replace() and eregi_replace()?

2 Answers   Quicknet,


What is php mean?

1 Answers  


What is difference between strstr() and stristr() in PHP?

1 Answers  


How to turn on the session support?

1 Answers  


Tell us what does $_cookie means?

1 Answers  


What is the php function that removes the first element of the array and returns it?

1 Answers  


Categories