+unabatedshagie Subscriber¹ Posted January 14, 2008 Subscriber¹ Share Posted January 14, 2008 Sorry for the topic title but I couldn't think what to put for it :D Anyway, I have a couple of books on php/mysql and some of the examples have $dbc = @mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) OR die ('Could not connect to MySQL: ' . mysql_error() ); while others will have $db = mysql_connect($dbhost, $dbuser, $dbpassword); so whats the difference between them? Link to comment Share on other sites More sharing options...
0 Esvandiary Posted January 14, 2008 Share Posted January 14, 2008 If I remember correctly, the @ symbol stops any errors from that command coming out (I've used it with an fsockopen() where I wanted my own output instead of the script's default error message). This is just my memory, though, so take it with a pinch of salt :rolleyes: EDIT: Yeah, I'm pretty sure that's right now; just removed it from the line I had it in on my little utilities page and it comes out with a warning that it timed out. :) Link to comment Share on other sites More sharing options...
0 deadpencil Posted January 14, 2008 Share Posted January 14, 2008 yep, that's right - it suppresses error messages other than that, there is no difference between your examples Link to comment Share on other sites More sharing options...
0 Esvandiary Posted January 14, 2008 Share Posted January 14, 2008 EDIT: Gah, you were too fast for me there ;) Link to comment Share on other sites More sharing options...
0 +unabatedshagie Subscriber¹ Posted January 14, 2008 Author Subscriber¹ Share Posted January 14, 2008 ok, thanks. So I would be better off leaving them off when I'm developing the site then adding them back in later when everything works? Link to comment Share on other sites More sharing options...
0 Belliash Posted January 14, 2008 Share Posted January 14, 2008 Depends on what are You trying to do... For example... You try to connect to database and You probably would like to know if Your website was unable to do so. If You don't use @ then it will just display an error message and probably die. However You may just want to display sth like "DB connect failed". To do so You write: if!(mysql_connect(...)) { die("DB connect fail"); } not sure about example i written above, if it will work, but that's one of easiest way to show how does @ work... Link to comment Share on other sites More sharing options...
0 +theblazingangel MVC Posted January 14, 2008 MVC Share Posted January 14, 2008 (edited) ok, thanks.So I would be better off leaving them off when I'm developing the site then adding them back in later when everything works? not advisable! instead, stick this at the top of your script: @ini_set('display_errors', 1); error_reporting(E_ALL); and then when your done developing, change it to: ini_set('display_errors', 0); error_reporting(0); use @ sparingly! Edited January 14, 2008 by theblazingangel Link to comment Share on other sites More sharing options...
0 rpgfan Posted January 14, 2008 Share Posted January 14, 2008 Using the @ operator is NOT advisable at all in a production environment. Why? Because it slows things down! If your server is getting hit by "The Digg Effect", your server will be slow for a while. In high-traffic cases such as that, you will want things to be as quick as possible, right? That is why things like this list were created. See tip #14 in that list. I personally would turn off display_errors, and turn on error logging. File I/O on the server side is often much faster than making a user wait for the browser only to see something like: Warning: mysql_connect(): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /home/.sites/64/site14/web/forums/mods/flashChat/inc/classes/db.php on line 23 Of course, that was from a Linux machine (or possibly a machine running UNIX or a UNIX clone), but the point stands. That list is only a couple of months old, so I would definitely recommend it. Link to comment Share on other sites More sharing options...
Question
+unabatedshagie Subscriber¹
Sorry for the topic title but I couldn't think what to put for it :D
Anyway, I have a couple of books on php/mysql and some of the examples have
while others will have
so whats the difference between them?
Link to comment
Share on other sites
7 answers to this question
Recommended Posts