List:General Discussion« Previous MessageNext Message »
From:Ing. Edwin Cruz Date:March 11 2006 5:34pm
Subject:RE: mysql_commect or die
View as plain text  
   mysql_connect("localhost","root") 
        or die("Unable to connect to MySQL server");

  $err = mysql_connect("localhost","root");
  if ($err != 0) {

Mysql_connect returns a link to a identifier of the conection, also returns
0 when the conection could not be estabished, 

When you do:
  $err = mysql_connect("localhost","root");
  if ($err != 0) {
	echo "Error: Unable to connect to MySQL server ".mysql_error();
  }
  else{
	[code]
  }
Is the same that this:
  $link = mysql_connect("localhost","root") or die("Unable to connect to
MySQL server ".mysql_error());
  [code]

The caluse "or die()"  after mysql_connect only will be launched if there is
an error, if not, the script continues its execution.

The $err variable has 0 if there is an error on that conditions.

And yes! Basically both are doing the same thing but if the conextion is
succesfully stablised it will have a link identifier of the conection.
Regards!


Edwin.



-----Mensaje original-----
De: fbsd_user [mailto:fbsd_user@stripped] 
Enviado el: Sábado, 11 de Marzo de 2006 10:56 a.m.
Para: Mysql
Asunto: mysql_commect or die


   mysql_connect("localhost","root") 
        or die("Unable to connect to MySQL server");

  $err mysql_connect("localhost","root");
  if ($err != 0) {


Under what conditions will the die clause be taken.

What is in $err  if there is a error?

Are these 2 statements basically doing the same thing?

 
 

-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/mysql?unsub=1


Thread
mysql_commect or diefbsd_user11 Mar
  • RE: mysql_commect or dieIng. Edwin Cruz11 Mar
  • Re: mysql_commect or diePeter Brawley11 Mar