Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

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

New Here ,
Apr 19, 2017 Apr 19, 2017

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

2.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Guru , Apr 19, 2017 Apr 19, 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: ');
}

Translate
Community Expert ,
Apr 19, 2017 Apr 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 & Moderator
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 19, 2017 Apr 19, 2017

Replace Deprecated Server Behaviors with a modern commercial extension:

Nancy

Nancy O'Shea— Product User, Community Expert & Moderator
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 19, 2017 Apr 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 & Moderator
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Apr 19, 2017 Apr 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Apr 19, 2017 Apr 19, 2017
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines