gpt4 book ai didi

php - 对 PDO 和 mysql_xxx 使用一个数据库连接

转载 作者:行者123 更新时间:2023-11-29 13:39:06 25 4
gpt4 key购买 nike

我在网站中使用 PDO,现在我需要一个使用 mysql_xxx 函数的 php 类。它本身不会连接和选择数据库,您应该像这样使用它:

    if (!($connection = @mysql_connect($MySQL_host, $MySQL_user, $MySQL_pass))) {
die('Error connecting to the database!'); }
if (!@mysql_select_db($MySQL_database, $connection)) {
die('Error selecting database!'); }

require '../Zebra_Mptt.php';
$mptt = new Zebra_Mptt();
$foo = $mptt->add(0, 'Foo');

我可以在 PDO 和 mysql_ 函数之间创建并共享连接或更有效的连接吗?

最佳答案

你不能。您必须为此创建两个单独的连接。但您也可以更改该类以使用 PDO 或找到另一个类。

关于php - 对 PDO 和 mysql_xxx 使用一个数据库连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18350493/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com