So I know that mysql_pconnect is deprecated, is there a way actually to make this work, I have an old script which in the connection file has the following:
$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();
}
Do I have an alternative to this?
//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();
}
this gives me "Cannot choose database, check if database name is correct."
You can use
mysqli
howeverPDO
is recommended for doing queries and plain php nowadays.