Knowledgebase: PHP & MySQL
Call to undefined function mysql_connect
Posted by Premium Reseller on 21 June 2019 02:59 AM

mysql_connect extension was deprecated in PHP 5.5.0, and it was removed in PHP 7.0.0.

MySQLi or PDO_MySQL extension should be used to connect mysql database from php script.



Sample connection string with mysqli:

$con = mysqli_connect('localhost', 'username', 'password', 'database');

Sample connection string with pdo-mysql:

$user = ''; // Mysql User
$password = ''; // Mysql Password
$server = 'localhost'; // Mysql Host
$database = 'my_database'; // Mysql Databse
// PDO Connection string
$pdo = new PDO("mysql:host=$server;dbname=$database", $user, $password);

(1 vote(s))
This article was helpful
This article was not helpful