所以我知道 mysql_pconnect 已被弃用,有没有办法真正做到这一点,我有一个旧脚本,在连接文件中有以下内容:
$success = mysql_pconnect ($mysql_host, $mysql_user, $mysql_password);
if (!$success)
die ("<b>Cannot connect to database, check if username, password and host are correct.</b>");
$success = mysql_select_db ($database);
if (!$success) {
print "<b>Cannot choose database, check if database name is correct.";
die();
}
我有其他选择吗?
//LE
try {
$success = new PDO("mysql:host=$mysql_host;dbname=$database", $mysql_user, $mysql_password, array(PDO::ATTR_PERSISTENT=>true));
} catch (PDOException $e) {
die ("<b>Cannot connect to database, check if username, password and host are correct.</b>");
}
$success = mysql_select_db ($database);
if (!$success) {
print "<b>Cannot choose database, check if database name is correct.";
die();
}
这给了我“无法选择数据库,请检查数据库名称是否正确。”