RE: [PHP] php die function for MySQL connection errors

2004-08-16 Thread Ford, Mike [LSS]
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

2004-08-16 Thread raditha dissanayake
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


Re: [PHP] php die function for MySQL connection errors

2004-08-14 Thread raditha dissanayake
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

2004-08-14 Thread Ford, Mike [LSS]
 -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

2004-08-14 Thread raditha dissanayake
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