Skip to main content
Participant
April 19, 2017
Answered

Help with the error Deprecated: mysql_pconnect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead

  • April 19, 2017
  • 3 replies
  • 2482 views

How do I change this code to the extension msqli or pdo so that the error goes away?

This topic has been closed for replies.
Correct answer Rob Hecker2

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: ');
}

3 replies

Nancy OShea
Community Expert
Community Expert
April 19, 2017

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

?>

Nancy O'Shea— Product User & Community Expert
Inspiring
April 19, 2017

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.

Rob Hecker2
Rob Hecker2Correct answer
Legend
April 20, 2017

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: ');
}

Nancy OShea
Community Expert
Community Expert
April 19, 2017
Nancy O'Shea— Product User & Community Expert
Nancy OShea
Community Expert
Community Expert
April 19, 2017

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>

Nancy O'Shea— Product User & Community Expert