Copy link to clipboard
Copied
How do I change this code to the extension msqli or pdo so that the error goes away?
Ebay is correct.
The following would work:
try {
$dbd = new PDO($db, $user, $pw, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
$dbd->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT);
}
catch (PDOException $e) {
die('Connection failed: ');
}
Copy link to clipboard
Copied
Which versions of PHP & MySQL do you have on your servers -- remote and local testing?
If you don't know, you can find out by running this script. SaveAs info.php Upload to server and open it in your browser.
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>PHP info</title>
</head>
<body>
<?php phpinfo() ?>
</body>
</html>
Copy link to clipboard
Copied
Replace Deprecated Server Behaviors with a modern commercial extension:
Nancy
Copy link to clipboard
Copied
MySQL test connection:
<?php
$conn = new mysqli('localhost' , 'username' , 'password' , 'database_name');
echo "<h1>Success in database connection! Happy Coding!</h1>";
// if no success the script would have died before this success message
?>
Copy link to clipboard
Copied
https://forums.adobe.com/people/Nancy+OShea wrote
// if no success the script would have died before this success message
Actually, without an explicit die argument the script will not die. The success message will still appear on the page. An access denied warning message will appear if the script is unable to connect to the database.
Copy link to clipboard
Copied
Ebay is correct.
The following would work:
try {
$dbd = new PDO($db, $user, $pw, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
$dbd->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT);
}
catch (PDOException $e) {
die('Connection failed: ');
}