Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2014-11-03
4
Medium Priority
?
1,279 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 111

Accepted Solution

by:
Ray Paseur earned 2000 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
In this article, we’ll look at how to deploy ProxySQL.
The viewer will learn how to dynamically set the form action using jQuery.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

718 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