bhuvan4700 Posted March 15, 2014 Share Posted March 15, 2014 I am getting huge errors in error log of my website. Like this [15-Mar-2014 12:34:34 America/New_York] PHP Warning: mysql_query() expects parameter 2 to be resource, boolean given in /home/ticket4t/public_html/management/include/connect.php on line 58 [15-Mar-2014 12:34:34 America/New_York] PHP Warning: mysql_close() expects parameter 1 to be resource, boolean given in /home/ticket4t/public_html/management/include/connect.php on line 138 [15-Mar-2014 12:34:34 America/New_York] PHP Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in /home/ticket4t/public_html/management/include/connect.php on line 87 [15-Mar-2014 12:34:34 America/New_York] PHP Warning: mysql_connect() [<a href='function.mysql-connect'>function.mysql-connect</a>]: Too many connections in /home/ticket4t/public_html/management/include/connect.php on line 34 [15-Mar-2014 12:34:34 America/New_York] PHP Warning: mysql_select_db() expects parameter 2 to be resource, boolean given in /home/ticket4t/public_html/management/include/connect.php on line 42 [15-Mar-2014 12:34:34 America/New_York] PHP Warning: mysql_query() expects parameter 2 to be resource, boolean given in /home/ticket4t/public_html/management/include/connect.php on line 58 [15-Mar-2014 12:34:34 America/New_York] PHP Warning: mysql_close() expects parameter 1 to be resource, boolean given in /home/ticket4t/public_html/management/include/connect.php on line 138 [15-Mar-2014 12:34:34 America/New_York] PHP Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in /home/ticket4t/public_html/management/include/connect.php on line 87 [15-Mar-2014 12:34:34 America/New_York] PHP Warning: mysql_connect() [<a href='function.mysql-connect'>function.mysql-connect</a>]: Too many connections in /home/ticket4t/public_html/management/include/connect.php on line 34 [15-Mar-2014 12:34:34 America/New_York] PHP Warning: mysql_select_db() expects parameter 2 to be resource, boolean given in /home/ticket4t/public_html/management/include/connect.php on line 42 [15-Mar-2014 12:34:34 America/New_York] PHP Warning: mysql_query() expects parameter 2 to be resource, boolean given in /home/ticket4t/public_html/management/include/connect.php on line 58 [15-Mar-2014 12:34:34 America/New_York] PHP Warning: mysql_close() expects parameter 1 to be resource, boolean given in /home/ticket4t/public_html/management/include/connect.php on line 138 [15-Mar-2014 12:34:34 America/New_York] PHP Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in /home/ticket4t/public_html/management/include/connect.php on line 87 [15-Mar-2014 12:34:34 America/New_York] PHP Warning: mysql_connect() [<a href='function.mysql-connect'>function.mysql-connect</a>]: Too many connections in /home/ticket4t/public_html/management/include/connect.php on line 34 [15-Mar-2014 12:34:34 America/New_York] PHP Warning: mysql_select_db() expects parameter 2 to be resource, boolean given in /home/ticket4t/public_html/management/include/connect.php on line 42 [15-Mar-2014 12:34:34 America/New_York] PHP Warning: mysql_query() expects parameter 2 to be resource, boolean given in /home/ticket4t/public_html/management/include/connect.php on line 58 [15-Mar-2014 12:34:34 America/New_York] PHP Warning: mysql_close() expects parameter 1 to be resource, boolean given in /home/ticket4t/public_html/management/include/connect.php on line 138 [15-Mar-2014 12:34:34 America/New_York] PHP Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in /home/ticket4t/public_html/management/include/connect.php on line 87 [15-Mar-2014 12:34:38 America/New_York] PHP Warning: mysql_connect() [<a href='function.mysql-connect'>function.mysql-connect</a>]: Too many connections in /home/ticket4t/public_html/management/include/connect.php on line 34 [15-Mar-2014 12:34:38 America/New_York] PHP Warning: mysql_select_db() expects parameter 2 to be resource, boolean given in /home/ticket4t/public_html/management/include/connect.php on line 42 [15-Mar-2014 12:34:38 America/New_York] PHP Warning: mysql_query() expects parameter 2 to be resource, boolean given in /home/ticket4t/public_html/management/include/connect.php on line 58 [15-Mar-2014 12:34:38 America/New_York] PHP Warning: mysql_close() expects parameter 1 to be resource, boolean given in /home/ticket4t/public_html/management/include/connect.php on line 138 [15-Mar-2014 12:34:38 America/New_York] PHP Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in /home/ticket4t/public_html/management/include/connect.php on line 87 given below is the code of connect.php Please help me to solve this problem. ------------------------------------------------------------------------------------------ <?php class dbcore { var $dblink, $dbhost, $dbuser, $dbpass, $dbname, $link, $Errno, $Error; function dbcore() { global $db_org; $this->getdblinks($db_org); } function getdblinks($pm_dbvars) { $this->dbhost = $pm_dbvars["dbhost"]; $this->dbuser = $pm_dbvars["dbuser"]; $this->dbpass = $pm_dbvars["dbpass"]; $this->dbname = $pm_dbvars["dbname"]; } function setdblinks($pm_dblink, $pm_dbhost, $pm_dbuser, $pm_dbpass, $pm_dbname) { $this->dbhost = $pm_dbhost; $this->dbuser = $pm_dbuser; $this->dbpass = $pm_dbpass; $this->dbname = $pm_dbname; } function siri_open() { global $wwwroot; $t_link = mysql_connect($this->dbhost, $this->dbuser, $this->dbpass); if(!$t_link) { // header("Location: ".$wwwroot."page-error"); $this->Errno = mysql_errno(); //$this->Error = mysql_error(); $this->error("Unable to Connect the Server".$this->dbhost); } $bool = mysql_select_db($this->dbname, $t_link); if(!$bool) { // header("Location: ".$wwwroot."page-error"); $this->Errno = mysql_errno(); //$this->Error = mysqli_error(); $this->error("Database Not Found :".$this->dbname); } return $t_link; break; } function siri_query($my_qry) { $this->link = $this->siri_open(); $qid= mysql_query ($my_qry, $this->link); $this->siri_close($this->link); if(!$qid){ $this->Errno = mysql_error(); $this->Error = mysql_error(); $this->error("Problem In Executing the Query:" . $my_qry); } return $qid; } function siri_count($my_qry) { // returns the count value. $this->link = $this->siri_open(); $qid = mysqli_query ($this->link, $my_qry); $this->siri_close($this->link); if(!$qid){ $this->Errno = mysqli_errno(); $this->Error = mysqli_error(); $this->error("Problem In Executing the Query:" . $my_qry); } $count = $this->siri_fetch_array($qid); return $count[0]; } function siri_fetch_array($qid) { return mysql_fetch_array($qid); } function siri_fetch_accos($qid) { return mysqli_fetch_assoc($qid); } function siri_real_escape_string($qid) { $this->link = $this->siri_open(); return mysqli_real_escape_string($qid); } function siri_fetch_row($qid) { return mysqli_fetch_row($qid); } function siri_fetch_object($qid) { return @mysqli_fetch_object($qid); } function siri_num_rows($qid) { $quy = mysql_num_rows($qid); return $quy; } function siri_affected_rows() { // for insert, update, delete reasons. return mysqli_affected_rows(); } function siri_insert_id() { return mysqli_insert_id($link); } function siri_insert_id1() { return mysqli_insert_id(); } function siri_free_result($qid) { mysqli_free_result($qid); } function siri_num_fields($qid) { return mysqli_num_fields($qid); } function siri_close($link) { mysql_close($link); } function error($msg) { printf("<b>Error : </b> %s<br>\n", $msg); printf("<b>MySQL Error</b>: %s (%s)<br>\n", $this->Errno, $this->Error); } function siri_fquery($qry,$val) { $qid = $this->siri_query($qry); while($re = $this->siri_fetch_array($qid)) { print"<option value=$re[0]"; ?> <?= ($val==$re[0])? "selected": "";?> <? print ">$re[1]</option>\n"; } } function siri_sinvalue($qry) { $qid = $this->siri_query($qry); $rs = $this->siri_fetch_array($qid); return $rs[1]; } function siri_drawNavigation($start,$total,$link) { if(($start%100)==0) { $j=$start/10+1; } else if($start/100>=1){ $j=intval(($start/100))*10+1; } else { $j=1; } if((intval($start/100))>1) { $temp=intval(($start/100-1))*10*10; } print "<div align=center>"; global $len; $check=$total%$len; if($check >=1 ) $lim=intval(($total/$len))+1; else $lim=intval($total/$len); print "<table cellpading=0 cellspacing=0 align=center width=100% nowrap><tr><td width=100%><table width=100% align=center ><tr><td width=100%>"; $en = $start +$len; // if($start==0 && $total>0){$start1=1;} else {$start1 = $start+1;} if($start==0){ if($total>0){ $start1=1; } else { $start1=0; } } else { $start1=$start+1; } if($en>$total) $en = $total; print "<font face=Verdana, Arial, Helvetica, sans-serif size=0 class='links1'>Showing $start1 - $en of $total <a href='$link&start=0'>Go to First Record</a> </font></td><td><!--<img src='../img/prev_button.gif' align=center>--><font face=Verdana, Arial, Helvetica, sans-serif size=1 class='links1'>" ; if($en>$len) { $en1=$start-$len; print "<a href='$link&start=$en1' class='links1'>Previous</a>" ; } else print "Previous"; print "</font>"; $temp1=1; print " <font face=Verdana, Arial, Helvetica, sans-serif size=1 class='links1'>" ; if($en<$total){ $en2=$start+$len; print "<a href='$link&start=$en2' class='links1'>Next</a>" ; } else print "Next"; print "</font></td></tr></table></td></tr></table></div>"; } function shrstr($string, $num="50") { // Check string length if grater then $num if (strlen($string) > $num) { // Shorten the string with ... $string = substr( $string, 0, $num-2); $string .= "..."; return $string; } else { // If $num is less then return $string; } } //////////////////////////////// function siri_insert_query($my_qry) { $this->link = $this->siri_open(); $qid = mysqli_query ($this->link, $my_qry); $lid = mysqli_insert_id($this->link); $this->siri_close($this->link); if(!$qid){ $this->Errno = mysql_errno(); $this->Error = mysql_error(); $this->error("Problem In Executing the Query:" . $my_qry); } return $lid; } }// end of the class ?> Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted March 15, 2014 Share Posted March 15, 2014 (edited) most of the errors are follow-on errors. they are caused because your database connection failed, but you didn't detect that in your code and stop your code from running and trying to use the non-existent connection. so, your code actually needs to test if the database connection worked before trying to run any query AND your code needs to test of the query worked (didn't fail due to an error) before trying to use the result from that query. this will eliminate most of the errors and just leave the most import error that started the whole problem. as to why your database connection is failing, it's because you/your-server has too many connections open and no more are permitted. this is typically caused by a server that has too many accounts hosted on it and doesn't permit enough database connections and/or i/we regularly see this problem when one script repeatedly opens and closes database connections, rather than just opening one connection and use that one connection for the duration of the script (i have a post somewhere on this forum theorizing that because it takes some time for the database server to actually close a connection and reduce the count of open connections, that a poorly written script that that opens and closes the database connection several times during its execution ends up consuming multiple database connections.) your code should NOT open a database connection, use it for one operation, then close the database connection. you should open one database connection and leave it open until you are completely done with it, then close it or simply let php automatically close it when the script ends. edit: your code is also mixing mysql (no i) and mysqli functions, has some @ error suppressors in it, and a lot of class methods simply wrap one php statement, and a lot of the functions are not using the proper parameters. in short, this code looks like it was thrown together with little planning and should be started over. Edited March 15, 2014 by mac_gyver Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.