php - mysql too many connection warning -


i keep getting following error when running cron job. runs every minute:

error

    <br /> <b>warning</b>:  mysqli_connect(): (08004/1040): many connections in <b>/home/eterna33/public_html/script/email_cron.php</b> on line <b>2</b><br />       <br />     <b>warning</b>:  mysqli_query() expects parameter 1 mysqli, boolean given in <b>/home/eterna33/public_html/script/email_cron.php</b> on line <b>6</b><br />     <br />     <b>warning</b>:  mysqli_fetch_array() expects parameter 1 mysqli_result, null given in <b>/home/eterna33/public_html/script/email_cron.php</b> on line <b>8</b><br />     <br />     <b>warning</b>:  mysqli_close() expects parameter 1 mysqli, boolean given in <b>/home/eterna33/public_html/script/email_cron.php</b> on line <b>19</b><br /> 

here code runs in cron job every minute.

<?php $con=mysqli_connect("localhost","**","****","***");    $result = mysqli_query($con, "select * mail status=false"); $count="0"; while($row = mysqli_fetch_array($result)) {         $count++;         mysqli_query($con, "update mail set status=true id='$row[id]'");         mail($row['send_to'], $row['subject'], $row['message'], $row['headers']);         mysqli_query($con, "delete mail status=true , id='$row[id]'");         if ($count >= 3) {             echo "exit";             mysqli_close($con);              exit;         }     }  mysqli_close($con); ?> 

i've contacted host "aren't trained" debug code. @ loss wrong. code functions normally, gives these errors.

you seem retrieving more information need, , abandoning partially read result set, each time run script. handle 3 items each time through. abandoned result sets not great database servers.

i suggest change query:

select * mail status=false 

to

select * mail status=false limit 3 

then, suggest change loop code follows:

$count = 0; while($row = mysqli_fetch_array($result)) {     $count++;     mysqli_query($con, "update mail set status=true id='$row[id]'");     mail($row['send_to'], $row['subject'], $row['message'], $row['headers']);     mysqli_query($con, "delete mail status=true , id='$row[id]'"); }  mysqli_close($con); if ($count > 0) {    echo "exit"; } 

it seems want echo command used if result set not empty, , still that. reads way through each result set.

also, doesn't fetch more rows need may more efficient.


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -