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.

mysqli_connect()

PDO::__construct()

https://www.php.net/manual/en/book.mysqli.php

https://www.php.net/manual/en/ref.pdo-mysql.php

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