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)

mysql_connect("anyfdgfgdgdfgddomain.com");

Output :
Warning: mysql_connect() [function.mysql-connect]: Unknown MySQL server host ‘anyfdgfgdgdfgddomain.com’ (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("anyfdgfgdgdfgddomain.com");
if( $con === false )
{
	echo "Could not connect to server.";
	exit();
}

Output :
Could not connect to server.

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

Share

You may also like...