PHP error control operator @

PHP error control operator is @. When this operator is prepended to any PHP expression then any error messages that might be generated by that expression will be ignored.

Sample (without @ operator)


Output :
Warning: mysql_connect() [function.mysql-connect]: Unknown MySQL server host ‘’ (1) in index.php on line 1

Here no username and password is mentioned and the host is also some random host. Mysql here cannot verify credentials so it flashed the above message.

Example (with @ operator)

$con = @mysql_connect("");
if( $con === false )
	echo "Could not connect to server.";

Output :
Could not connect to server.

We have prefixed @ symbol in front of mysql_connect(“”); So custom message will be displayed.


You may also like...