Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deprecated: mysql_pconnect():

Tags:

php

mysql

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
checking

The inner code looks this way

http://justpaste.it/eyk2

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_select_db($database_conn);
mysql_query("SET NAMES UTF8");
like image 544
user3493204 Avatar asked Apr 03 '14 10:04

user3493204


2 Answers

See the documentation for mysql_pconnect:

Alternatives to this function include:

mysqli_connect() with p: host prefix

So use mysqli_connect, not mysqli_pconnect and modify the host argument as described

like image 94
Quentin Avatar answered Nov 14 '22 16:11

Quentin


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.

like image 26
rubo77 Avatar answered Nov 14 '22 15:11

rubo77