php 弃用:mysql_pconnect():

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22834458/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 16:18:22  来源:igfitidea点击:

Deprecated: mysql_pconnect():

phpmysql

提问by user3493204

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

我在 php 执行过程中遇到错误,我认为这是由于更新的 php 5.5 问题。

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

已弃用::mysql_pconnect()不推荐使用 mysql 扩展并将在将来删除:在
2014 年 4 月 3 日第 7 行
检查中,在 /public_html/mydomain.com/connx.php 中使用 mysqli 或 PDO 代替

The inner code looks this way

内部代码看起来像这样

http://justpaste.it/eyk2

http://justpaste.it/eyk2

So i thought changing the mysqlto mysqlicould solve the issue :

所以我认为改变mysqltomysqli可以解决问题:

$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()

致命错误:调用未定义的函数 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

无论如何我可以解决这个问题?该代码是很久以前构建的,现在我无法真正与他取得联系: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 ?

谢谢 ** 更新 ** 我更改了 mysqli_connect,当我加载 php 脚本时...它现在显示的错误很少...只是想知道我是否也必须更改这些语法?

mysql_select_db($database_conn);
mysql_query("SET NAMES UTF8");

回答by Quentin

See the documentation for mysql_pconnect:

请参阅以下文档mysql_pconnect

Alternatives to this function include:

mysqli_connect()with p: host prefix

此功能的替代方案包括:

mysqli_connect()带 p:主机前缀

So use mysqli_connect, not mysqli_pconnectand modify the host argument as described

所以使用mysqli_connect, notmysqli_pconnect并按照描述修改主机参数

回答by rubo77

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

没有“mysqli_pconnect”,但您可以mysqli_connect()通过添加p:到主机名的开头来建立持久连接。

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

因此,您可以通过将其添加到 php 文件的头部来恢复旧样式:

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_pconnectwith mysql_connectin your scripts anyway.

更新:由于 pconnects 几乎没有任何好处,因此无论如何您都应该在脚本中替换mysql_pconnectwith mysql_connect

回答by Spudley

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.

没有mysqli_pconnect(),但你可以使用永久连接mysqli_connect()手册中描述,只需添加p:到主机名的开头。

Quote from the manual:

引用手册:

Prepending host by p: opens a persistent connection.
Prepending host by p: opens a persistent connection.