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,258 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 58

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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

617 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