Page 1 of 1

[SOLVED]three tries before show any error message db connec.

Posted: Mon Nov 20, 2006 2:01 pm
by visonardo
the file that im using so much is

conection.php

Code: Select all

function Conectarse() 
{ 
   if (!($link=mysql_connect("host", "user", "password"))) 
   { 
      echo "Error conectando a la base de datos."; 
      exit(); 
   } 
   if (!mysql_select_db('db_name',$link)) 
   { 
      echo "Error seleccionando la base de datos."; 
      exit(); 
   } 
   return $link;
} 
?>
of course, i use that thus

Code: Select all

include('conection.php');
$linkdb=conectarse();
but im in a soooo important task and in sometimes its stoped because the db connection failed. Then i thought the file to do three tries thus

Code: Select all

function Conectarse() 
{ 
   $try=0;
do{
$link=mysql_connect("host", "user", "password");
$try++; 
 }while(!$link && $try<3);
 if(!$link){
      echo "Error conecting to db."; 
      exit(); 
} 
$try=0;
  do{
$a=mysql_select_db('db_name',$link); 
$try++;   
}while(!$a && $try<3);
if(!$a){
      echo "Error selecting db."; 
      exit(); 
   } 
   return $link;
} 
?>

but dont work :? mysql_error(); say "the query was empty" :o

what is bad here?

Posted: Mon Nov 20, 2006 2:23 pm
by volka
visonardo wrote:but dont work :? mysql_error(); say "the query was empty" :o
There is no mysql_error() in this code snippet

Posted: Mon Nov 20, 2006 2:36 pm
by visonardo
volka wrote:
visonardo wrote:but dont work :? mysql_error(); say "the query was empty" :o
There is no mysql_error() in this code snippet
the mysql_error() is when im using mysql_query

Posted: Mon Nov 20, 2006 4:49 pm
by volka
Then show us that mysql_query

Posted: Mon Nov 20, 2006 5:19 pm
by visonardo
nothing, now it work fine. Thank :wink:

Posted: Mon Nov 20, 2006 5:45 pm
by Luke
visonardo wrote:nothing, now it work fine. Thank :wink:
Your