I have no problem connecting to a database using PHP however in some scripts I have tested, I have seen a small difference in the connect command.
What is the difference between @mysql_connect
and mysql_connect
?
I have never used the @
symbol when writing my own script so was just wondering if it served a purpose.
Thanks in advance
There are several important differences between the two libraries: Mysqli supports charsets, mysql does not. Mysqli supports prepared statements, mysql does not. Mysql does not support multiple statements, mysqli does.
This extension was deprecated in PHP 5.5. 0, and it was removed in PHP 7.0.
mysql_connect() establishes a connection to a MySQL server. The following defaults are assumed for missing optional parameters: server = 'localhost:3306', username = name of the user that owns the server process and password = empty password. The server parameter can also include a port number.
The @
symbol in front of a function silences it. Meaning, you won't get any types of error messages when executing it, even if it fails. So I suggest: don't use it
In addition as @AlexanderLarikov said, don't use mysql_*
anymore, the community has started to depreciate that function.
It is the/an error control operator. It simply allow you to suppress the error.
I would suggest that you omit it in your code.
From documentation:
Currently the "@" error-control operator prefix will even disable error reporting for critical errors that will terminate script execution. Among other things, this means that if you use "@" to suppress errors from a certain function and either it isn't available or has been mistyped, the script will die right there with no indication as to why.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With