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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
visonardo
Forum Contributor
Posts: 136
Joined: Mon Oct 02, 2006 7:49 pm
Location: Argentina, South America´s Sun.

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

Post 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?
Last edited by visonardo on Mon Nov 20, 2006 5:20 pm, edited 1 time in total.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

visonardo wrote:but dont work :? mysql_error(); say "the query was empty" :o
There is no mysql_error() in this code snippet
User avatar
visonardo
Forum Contributor
Posts: 136
Joined: Mon Oct 02, 2006 7:49 pm
Location: Argentina, South America´s Sun.

Post 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
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Then show us that mysql_query
User avatar
visonardo
Forum Contributor
Posts: 136
Joined: Mon Oct 02, 2006 7:49 pm
Location: Argentina, South America´s Sun.

Post by visonardo »

nothing, now it work fine. Thank :wink:
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

visonardo wrote:nothing, now it work fine. Thank :wink:
Your
Post Reply