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,200 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
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 54

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 109

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Download tables into separate sheets 3 27
write screen output to text file 21 47
Presenting past 6 months bug 7 27
000webhost.com default error log 1 28
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…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

770 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