[PHP] die function
Hi all, I have a machine that must insert in cron in a mysql db in another remote machine. The problem is that I cannot know if the connection in the first machine (adsl) go down because no entry in the machine log is generated. I would like to redirect the die function in a e-mail that say me what happens. I found a script ?php function die_script($errmsg) { print $errmsg . /body/html; die; } ? and I tried to insert a mail() before die function but I cannot call the function in this way: or die(Connection failed: . die_script()); But no email is generated. How can I do? Thanks Barbara -- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] php die function for MySQL connection errors
On 14 August 2004 15:50, raditha dissanayake wrote: Ford, Mike [LSS] wrote: (And, BTW, the HTTP definition says that the Location: header should specify a full absolute URL, so that should be: header(Location: http://your.server.name/path/to/errors/servererror.php;); are you sure? Yes. In fact, I was too conservative -- the HTTP RFC says it *must*. See: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.30 and http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.2 Just because many browsers accept and process a non-standard header is no reason to write non-standard headers... ;) Cheers! Mike - Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning Information Services, JG125, James Graham Building, Leeds Metropolitan University, Headingley Campus, LEEDS, LS6 3QS, United Kingdom Email: [EMAIL PROTECTED] Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] php die function for MySQL connection errors
Ford, Mike [LSS] wrote: On 14 August 2004 15:50, raditha dissanayake wrote: Ford, Mike [LSS] wrote: (And, BTW, the HTTP definition says that the Location: header should specify a full absolute URL, so that should be: header(Location: http://your.server.name/path/to/errors/servererror.php;); are you sure? Yes. In fact, I was too conservative -- the HTTP RFC says it *must*. See: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.30 and http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.2 Just because many browsers accept and process a non-standard header is no reason to write non-standard headers... ;) Thanks mike, just when i started to think i was an expert in this field you burst my ego :-) -- Raditha Dissanayake. http://www.radinks.com/sftp/ | http://www.raditha.com/megaupload Lean and mean Secure FTP applet with | Mega Upload - PHP file uploader Graphical User Inteface. Just 128 KB | with progress bar. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] php die function for MySQL connection errors
Hi, I have a quick question about using the PHP die() function. I'm building a site around a MySQL database, and when I connect to the database from a PHP page I use the following code: $connection = mysql_connect($host, $user, $password) or die(Error connecting to SQL server); $db = mysql_select_db($database, $connection) or die('Error connecting to database); Simple enough so far right? So if there is a problem connecting in anyway, an error message appears. What I want though is to redirect to a properly separate error page, rather than just have a basic text mesage. I changed the code to this: $connection = mysql_connect($host, $user, $password) or die(Error connecting to SQL server); $db = mysql_select_db($database, $connection) or header('Location: ../errors/databaseselect.php'); Which works fine (tested by deliberately misnaming database so it can't find it). However if I then use the same approach for the server connection error, like below, it doesn't work. $connection = mysql_connect($host, $user, $password) or header('Location: ../errors/servererror.php'); $db = mysql_select_db($database, $connection) or header('Location: ../errors/databaseselect.php'); I get a variety of error messages dependant on what I tweek to try and make it work. I've tried all I can think of, and I've tried putting the header function inside a die function to no avail. I don't understand why it works for the database connect error but not the server error. If anyone has any suggestions as to what the problem is or how I could improve my technique I'd love to know. I'm sure I can't be the only person who has wanted to do something like this, but I can't find any references online to anything other than simple text error messages. I'm relatively new to PHP but not programming in general so please don't be afraid to fire big words at me. Thanks in advance! John G -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] php die function for MySQL connection errors
John Gostick wrote: Hi, I have a quick question about using the PHP die() function. I'm building a site around a MySQL database, and when I connect to the database from a PHP page I use the following code: $connection = mysql_connect($host, $user, $password) or die(Error connecting to SQL server); $db = mysql_select_db($database, $connection) or die('Error connecting to database); you haven't told us what error messages you are getting - however my guess is that your header() call fails because of the error message produced by mysql_connect() if so you can try @mysql_connect($host, $user, $password) instead so that error messages to browser are suppressed ( you can achieve the same by editing your php.in) -- Raditha Dissanayake. http://www.radinks.com/sftp/ | http://www.raditha.com/megaupload Lean and mean Secure FTP applet with | Mega Upload - PHP file uploader Graphical User Inteface. Just 128 KB | with progress bar. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] php die function for MySQL connection errors
-Original Message- From: John Gostick Sent: 14/08/04 15:19 I have a quick question about using the PHP die() function. [...] I changed the code to this: $connection = mysql_connect($host, $user, $password) or die(Error connecting to SQL server); $db = mysql_select_db($database, $connection) or header('Location: ../errors/databaseselect.php'); Which works fine (tested by deliberately misnaming database so it can't find it). However if I then use the same approach for the server connection error, like below, it doesn't work. $connection = mysql_connect($host, $user, $password) or header('Location: ../errors/servererror.php'); On failure, this causes the header to be sent, but doesn't actually stop execution of your script, so... $db = mysql_select_db($database, $connection) this will now fail because you don't have a valid $connection. or header('Location: ../errors/databaseselect.php'); The bottom line is, whenever you issue a header(Location: ) call, you also need to cause the script to die if your logic demands that -- so the above should be written something like: if (!$connection = mysql_connect($host, $user, $password)): header('Location: ../errors/servererror.php'); die(); endif; if (!$db = mysql_select_db($database, $connection)): header('Location: ../errors/databaseselect.php'); die(); endif; (And, BTW, the HTTP definition says that the Location: header should specify a full absolute URL, so that should be: header(Location: http://your.server.name/path/to/errors/servererror.php;); etc.) Cheers! Mike -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] php die function for MySQL connection errors
Ford, Mike [LSS] wrote: (And, BTW, the HTTP definition says that the Location: header should specify a full absolute URL, so that should be: header(Location: http://your.server.name/path/to/errors/servererror.php;); are you sure? -- Raditha Dissanayake. http://www.radinks.com/sftp/ | http://www.raditha.com/megaupload Lean and mean Secure FTP applet with | Mega Upload - PHP file uploader Graphical User Inteface. Just 128 KB | with progress bar. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php