Jump to content

[SOLVED] php mysql fire function question


calmchess

Recommended Posts

I'm useing the following script to connect to an sql database now after it connects and everything a function is being called and information from  the database is being passed as parameters....my question is how do i stop that sigSucc function from firing if a connection to the database cannot be established ? i was thinking of using an if statement but I don't know what  event is called or what data is returned  when a successful connection is made ....could somebody plz shed some light on this subject for me.

 

<?

//connect to db

$conn = mysql_connect("localhost", "root", "KKT1pKT2KKT1pKT2") or die(mysql_error());

mysql_select_db('refid', $conn) or die(mysql_error());

  global $conn;

 

  //query database

  $q = mysql_query ("select * from  vidref");

 

  //fetch row from database

  while($row = mysql_fetch_array($q))

  {

  //get count from database record

  $counter0=$row['vidid'];

 

  }

 

//??????want if statement to fire sigSucc function only after a successful connection and query to the database has been made?????????

sigSucc($counter0,$totUsers0,$q,$conn);

 

?>

Link to comment
https://forums.phpfreaks.com/topic/82700-solved-php-mysql-fire-function-question/
Share on other sites

You have this code

 

<?
//connect to db
$conn = mysql_connect("localhost", "root", "KKT1pKT2KKT1pKT2") or die(mysql_error());

 

The 'or die' part basically means that if the connection to the database fails, then no code after the line above will be executed (read and carried out). So your function won't be executed if there is no database connection anyway, no need for extra code.

 

If you must insist on re-arranging your code (even though you don't need to), then you can try this:

 

<?
//connect to db
$conn = mysql_connect("localhost", "root", "KKT1pKT2KKT1pKT2");
mysql_select_db('refid', $conn) or die(mysql_error());
   global $conn;

   //query database
   $q = mysql_query ("select * from  vidref");
   
   //fetch row from database
   while($row = mysql_fetch_array($q))
   {
   //get count from database record
   $counter0=$row['vidid'];

   }

//?Huh??want if statement to fire sigSucc function only after a successful connection and query to the database has been made?HuhHuh??

if ( $conn )
{
  sigSucc($counter0,$totUsers0,$q,$conn);
}

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.