Solved

How do I stop a website displaying a 'mysql_connect(): The mysql extension is deprecated' PHP error?

Posted on 2014-11-03
4
1,239 Views
Last Modified: 2014-11-04
I am having a problem with a PHP website and require assistance if poss.

The site is displaying the following error. I believe that it could be due to the server configuration.

mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead  /var/www/xxxxxxxxxxx_main/includes/common/sql.php  Line 51

Please could anyone help me troubleshoot and resolve this issue?
0
Comment
Question by:phaygarth
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 7

Expert Comment

by:Stampel
ID: 40419754
If you just intend to hide the message, use a @ in front of the function to suppress warning like :
$con = @mysql_connect(DBHOST, DBUSER, DBPASS);
and test $con return with mysql_error

but if you can, install PDO and use PDO function as instructed to do :)
0
 
LVL 36

Expert Comment

by:Loganathan Natarajan
ID: 40419800
FYI, old mysql_* functions are deprecated in PHP 5.5 (http://php.net/manual/en/changelog.mysql.php).  Try to avoid using them Or convert into mysqli.

<?php
$link = mysqli_connect('localhost', 'user', 'password', 'dbname');

Open in new window


ref. http://php.net/manual/en/book.mysqli.php
0
 
LVL 57

Expert Comment

by:Julian Hansen
ID: 40419840
Hiding the message might fix the problem now but as soon as your server is upgraded to 5.5 your website will stop working.

You might want to consider to moving over to mysqli as soon as possible - this can be easy or difficult depending on how your site has been built.

If you use an abstraction layer then the process is simple - you just implement or install a mysqli connector or update your abstraction layer code to use mysqli.

If however you have used native mysql calls throughout your code then you have a lot of manual labour and testing ahead of you.

If you are going to change your code consider using an abstraction layer to connect to mysql.
0
 
LVL 110

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 40419906
All PHP functions are documented in the online man pages.  For example, see the large red warning box here:
http://www.php.net/manual/en/function.mysql-connect.php

Here is an article that takes you step-by-step through what you must do:
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/PHP_Databases/A_11177-PHP-MySQL-Deprecated-as-of-PHP-5-5-0.html

The short-term "fix" is not really a fix, but it may help you suppress the messages temporarily while you remediate the code:
<?php
error_reporting(E_WARNING ^ E_DEPRECATED);

Open in new window

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question