Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@mysql_connect and mysql_connect

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

like image 992
Lodder Avatar asked Jul 31 '12 14:07

Lodder


People also ask

What is the difference between mysql_connect and mysqli_connect?

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.

Is mysql_connect deprecated?

This extension was deprecated in PHP 5.5. 0, and it was removed in PHP 7.0.

What are the parameters of mysql_connect?

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.


2 Answers

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.

like image 147
Peon Avatar answered Oct 23 '22 14:10

Peon


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.

like image 31
JK. Avatar answered Oct 23 '22 14:10

JK.