Connection string to connect MySQL in PHP | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Connection string to connect MySQL in PHP

How to connect to a MySQL database in PHP?

26th Feb 2017, 12:13 PM
Arbaz Alam
Arbaz Alam - avatar
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
26th Feb 2017, 7:21 PM
Mohammed Shamshid
Mohammed Shamshid - avatar
0
<? php $ conn=mysql_connect ("host", "user", "password", "database"); if (! $ conn) { die ('could not connect to database: ' . mysql_error () ); } ?>
26th Feb 2017, 4:47 PM
Raj Kumar Chauhan
Raj Kumar Chauhan - avatar
0
Do not use MySQL, it's deprecated!
26th Feb 2017, 7:14 PM
Dev
Dev - avatar