Message when run index.php

Below message display when open url index.php

Deprecated : mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in
C:\xampp\htdocs\inexsmo\newsadmin\config.php on line 48

The website is using an old method to communicate with the database and needs to be changed to a more modern method. This is something that needs be changed throughout the entire codebase, and we can’t just give you a quick fix for that.

1 Like

The only way to remove that message is to either refactor the code or disable deprecation errors.If the site is working in production and you are local then disabling deprecation warnings is an option until time/budget allows for a complete refactor and/or server upgrade to a newer version of php.If the script is something that does not exist on a production server then chances are that it will not work at all when released to production server unless that server is using a very old version of php.

It also means the version of PHP you are using is outdated.
In version 5.6 it is deprecated. All support for 5.6 ends today.
In versions 7 onward it mysql is removed altogether, so you would get an “undefined function” error instead.

So really in the not too distant future you need to update your php version to 7.2 or 7.3 and start using mysqli or pdo.
http://php.net/supported-versions.php

Getting sign-off for a budget to make large changes like that which add little user facing value can be very difficult depending on the scale or project and organization. Especially if the project is written so poorly that nearly every single file needs to be changed. Not to mention for many organizations migrating from <7 to 7 can be a very expensive task. For small, sites hosted on shared server where one developer manages everything including hosting I would agree but for other cases where there is managed infrastructure there is much more involved, both from a technical and political aspect. For large organizations and projects it is probably better to consider rebuilding the project using modern technology that might not include php then to update the code or migrate to a new major version.

True.
We just don’t know the specific circumstances of the OP’s site.
We can see they are developing locally with xamp, but is there an existing live version too?
Given the “old” code, probably yes, but only the OP can tell us.

But at the same time below is working fine using same database on same pc and same version of php

http://localhost:8080/inexsmo/
but
below is not working, It gives message as I have posted query for the same
http://localhost:8080/inexsmo/newsadmin/index.php

We can’t see stuff on your localhost address.

what could be possible checklist ?
Note : as it is using same database and same php version

In online both working at presently.
When try to test at localhost/newsadmin is give this message

Is it just your error reporting settings?
Generally you won’t be deisplaying errors on the live host, but you will on the local envionment.
What about the logs on the live server?

That I have to check in online as you have said.
But what is about the localhost ?
I have to run test code at localhost first to check then only upload it to online.
Without connect mysql_connect() at localhost it can not possible.

Well the thing is, mysql will still work in 5.6, this is only a warning as opposed to an actual error.
So you could alter the reporting to ignore it for now.

But still be aware, it does mean you are using obsolete code and an obsolete php version and there are security concerns that go with that.
It may not be practical to make the changes just now, but it is something you need to start looking at.

When that time comes, first change your scripts to use PDO (I would recommend over mysqli). Only when you have that working you can upgrade the php version.
Upgrading php first will stop things working altogether, because the newer versions don’t support mysql at all.

Thanks for show me right path.
As per your suggestion in long term I have to think about the upgrade php version.
At present to stop the message and warning, I had modify my index.php with below
“error_reporting(E_ALL);”
Put above line top of index.php As below

<?php
error_reporting(E_ALL);
include 'config.php';

if(isset($_POST['submit']))    
{

}
else
{

}
?>
<!DOCTYPE html>
 <html lang="en">
<head>
  <title>INEX</title>
  ....
<body>
....
</body>
</html>

Note : still message / warning is display when open index.php at localhost
my index page is containing html and php for simple login using mysql database

As per the doc, that turns on all PHP error messages, not off.

http://php.net/manual/en/function.error-reporting.php

AFAIK, that is only since version 5.4 (?) and prior to that E_STRICT / E_DEPRECATED errors / warnings were not included in E_ALL

I certainly hope no one would be writing new code for versions that have long stopped getting support. Well, maybe for learning purposes only, maybe. But certainly not for anything meant to go into a live site.

@bjbhatttalk Do you know what version you are working with? What happens if you change the line to

 error_reporting(-1); 

I half-read a note about something changing part-way through. Using E_ALL would never have turned them all off, as far as I can tell.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.