23

I am working on project @ home and using WAMP for development. Currently the php.ini file has the following lines set like this:

error_reporting = E_ALL & ~E_DEPRECATED
display_errors = On

I had hoped in doing so it would prevent deprecation warnings from showing up. However it is not. Is there a way I can adjust error_reporting to ignore deprecated warnings.

Output I am getting currently:

Screen of the problem

Javacadabra
  • 5,578
  • 15
  • 84
  • 152
  • 2
    [**Don't use `mysql_*` functions in new code**](http://bit.ly/phpmsql). They are no longer maintained [and are officially deprecated](http://j.mp/XqV7Lp). See the [**red box**](http://j.mp/Te9zIL)? Learn about [*prepared statements*](http://j.mp/T9hLWi) instead, and use [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli) - [this article](http://j.mp/QEx8IB) will help you decide which. (Also, possible duplicate of [Turn off deprecated errors php 5.3](http://stackoverflow.com/questions/2803772/turn-off-deprecated-errors-php-5-3).) – esqew Jul 03 '14 at 17:25
  • 3
    Do you actually have `&` in your php.ini? – gen_Eric Jul 03 '14 at 17:27
  • 2
    While code is being converted to MySQLi/PDO, E_DEPRECATED errors can be suppressed by setting error_reporting in php.ini to exclude E_DEPRECATED: `error_reporting = E_ALL ^ E_DEPRECATED` – NullPoiиteя Jul 03 '14 at 17:30
  • btw its not recommended to do so better to use pdo also check this http://stackoverflow.com/a/14110189/1723893 – NullPoiиteя Jul 03 '14 at 17:31
  • cross-check your php.ini file path from phpinfo() and do it. It should work – Kuppusamy May 11 '20 at 10:51

6 Answers6

35

You can use this function :

error_reporting(E_ALL ^ E_DEPRECATED);

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

Or use "@" operator before function name.

@mysql_connect();
robsch
  • 9,358
  • 9
  • 63
  • 104
user2226755
  • 12,494
  • 5
  • 50
  • 73
  • 3
    Thanks, Using PHP 5.5.9 on Ubuntu error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT Have no effect.... but "@mysql_connect();" do the trick – molokoloco Feb 04 '16 at 14:38
20

In your php.ini file change the following.. (note wamp has 2 different php.ini files so make the changes on both)

from this

error_reporting = E_ALL

to this

error_reporting = E_ALL & ~E_DEPRECATED
Nic
  • 6,211
  • 10
  • 46
  • 69
Ryan Augustine
  • 1,455
  • 17
  • 14
6

I had the same problem. It turned out however, that I edited wrong php.ini file. In my case the correct one was

C:\wamp64\bin\php\php5.6.25\phpForApache.ini

and in this file I have changed this line to:

error_reporting = E_ALL & ~E_DEPRECATED.

It didn't make any difference what I had changed in that "obvious" php.ini file.

n-dru
  • 9,285
  • 2
  • 29
  • 42
3

Set your error report to

error_reporting (E_ERROR | E_WARNING | E_PARSE | E_NOTICE);

on your php page.

Martin
  • 22,212
  • 11
  • 70
  • 132
seyi_php
  • 31
  • 1
2

If you want to show all errors except deprecated, then use this setting:

error_reporting = E_ALL ^ E_DEPRECATED

Edit: You could also create a custom error handler to hide only mysql_ deprecation warnings:

set_error_handler(function($errno, $errstr) {
    return strpos($errstr, 'mysql_') === 0;
}, E_DEPRECATED);

But please note that mysql_ functions are deprecated. So instead of trying to hide the errors, consider switching to mysqli or PDO.

Gergo Erdosi
  • 40,904
  • 21
  • 118
  • 94
2

To hide php errors on WAMP server, Please open php.ini file and find following line of code

error_reporting = E_ALL

and replace it with

error_reporting = E_ALL & ~E_NOTICE

All errors will be hide/disable.

Ramesh Kumar
  • 542
  • 2
  • 10
  • 19