i am getting an error during a php execution which i think it was due to a newer php 5.5 thing.

Deprecated: mysql_pconnect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /public_html/mydomain.com/connx.php on line 7
Apr 3, 2014

The inner code looks this way


So i thought changing the mysql to mysqli could solve the issue :

$conn = mysqli_pconnect($hostname_conn, $username_conn, $password_conn) or trigger_error("Server Down"); 

And instead, I'm getting this error... so i guess it was not the correct way of doing so :)

Fatal error: Call to undefined function mysqli_pconnect()

anyhow i can fix this issue ? The code was built long time ago and now i cant really get in touch with him :x

thanks ** UPDATED ** I changed the mysqli_connect and when i load the php script... it shows few errors now... just wondering do i have to change these syntax too ?

mysql_query("SET NAMES UTF8");
      • 2
    • Besides what @Quentin says, use variable binding technique (WHERE name=? -> mysqli_stmt_bind_param) instead of the old fashion stuff-everything-into-my-sql-statement WHERE name='$name'.

There is no "mysqli_pconnect", but you can make persistent connections using mysqli_connect() by adding p: to the beginning of the hostname.

So you can restore the old style by adding this to the head of your php file:

if (!function_exists("mysql_pconnect")){
    function mysql_pconnect($host, $username, $password){
        return mysqli_connect("p:".$host, $username, $password);

UPDATE: As pconnects have nearly no benefit, you should replace mysql_pconnect with mysql_connect in your scripts anyway.

  • 5
Reply Report

There is no mysqli_pconnect(), but you can make persistent connections using mysqli_connect() as described in the manual, simply by adding p: to the beginning of the hostname.

Quote from the manual:

Prepending host by p: opens a persistent connection.
  • 0
Reply Report
      • 2
    • changing mysql_select_db($database_conn) to mysqli_select_db($database_conn) and mysql_query("SET NAMES UTF8") to mysqli_query("SET NAMES UTF8"); ?
    • @user3493204: There are subtle differences between the mysql and mysqli APIs. for example, you will need to provide $database_conn as the first argument of mysqli_query(). Also note, that mysqli provides the mysqli_set_charset() function, which replaces the need to make a SET NAMES query. See the manual page: quote: This is the preferred way to change the charset. Using mysqli_query() to set it (such as SET NAMES utf8) is not recommended.
      • 2
    • Thanks guys, the problem is actually the script is fetching some data, not sure if i hide this reporting, the fetching may fail or not. (will not be using this hidden option) In the mean time, i tried to edit it to mysqli_connect and more error when im running the script.. i guess this is gonna change as well ? mysql_select_db($database_conn); mysql_query("SET NAMES UTF8");
      • 2
    • Yes, if you change one mysql_ function call to mysqli then you must change them all -- they are completely separate database drivers (even though they ultimately talk to the same DB); you can't mix and match between them. A connection opened via mysqli can't be used by the mysql functions and vice-versa.

Warm tip !!!

This article is reproduced from Stack Exchange / Stack Overflow, please click

Trending Tags

Related Questions