0
Connection string to connect MySQL in PHP
How to connect to a MySQL database in PHP?
3 Answers
+ 1
There are 3 methods of connection to database and they are mysql, mysqli and PDO. Mysql is deprecated in PHP 5 and removed in PHP 7+.
Use MySQLi instead
here is a simple method to connect:
$server = "server";
$username = "username";
$password = "secret";
$database = "database-name";
$conn = mysqli_connect($server, $username, $password, $database);
PDO can be used to connect 12 types of databases while Mysqli can only connect to MySQL
0
<? php
$ conn=mysql_connect ("host", "user", "password", "database");
if (! $ conn)
{ die ('could not connect to database: ' . mysql_error () );
}
?>
0
Do not use MySQL, it's deprecated!