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,162 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
4 Comments
 
LVL 7

Expert Comment

by:Stampel
Comment Utility
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
Comment Utility
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 51

Expert Comment

by:Julian Hansen
Comment Utility
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 108

Accepted Solution

by:
Ray Paseur earned 500 total points
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

762 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now