jesbin Posted April 14, 2010 Share Posted April 14, 2010 I've a DataManager class which looks like the following <?php class DataManager { protected static $link; private static function _getConnection($dbname = 'wgexpert') { if (isset(self::$link)) return self::$link; self::$link = mysql_connect('localhost', 'root', '' ); $db = mysql_select_db('wgexpert') or die('Failure to access the database'); return (self::$link); } public static function getcountries() { $sql = "call spGetCountries();"; $countries = array(); $result = mysql_query($sql, DataManager::_getConnection()); while ($row = mysql_fetch_array($result)) { $countries[$row["countryID"]] = $row["countryName"]; } return ($countries); } public static function getNominators($name, $org, $country) { $sql = "call spSearchNominator('$name', '$org', $country);"; $res = mysql_query($sql, DataManager::_getConnection()); while ($row = mysql_fetch_array($res)) { / * do something */ } } } ?> There there is a php page which calls two of the method of the class require_once("classes/class.DataManager.php"); $data = DataManager::getcountries(); print_r($data); DataManager::getNominators ("b", "", 0); If I call both of then I get the error while calling the second method. If I comment out one of them (any one), it is fine. I cannot figure out what is going on Jesbin Quote Link to comment https://forums.phpfreaks.com/topic/198516-problem-with-multiple-mysql-calls-on-a-static-php-class/ Share on other sites More sharing options...
fenway Posted April 17, 2010 Share Posted April 17, 2010 I see no errors posted. Quote Link to comment https://forums.phpfreaks.com/topic/198516-problem-with-multiple-mysql-calls-on-a-static-php-class/#findComment-1043720 Share on other sites More sharing options...
jesbin Posted April 17, 2010 Author Share Posted April 17, 2010 The error I get is Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\Work\IPCC\Search.php\classes\class.DataManager.php on line 189 Array ( ) This is always the case for the second call. If I switch then around I get it for the second one. The workaround I did was to close the mysql connection, which is not what I wanted to do private static function _getConnection($dbname = 'wgexpert') { if (isset(self::$link)) { mysql_close(self::$link); // THIS HAD TO BE DONE } self::$link = mysql_connect('localhost', 'root', '', true ); $db = mysql_select_db('wgexpert') or die('Failure to access the database'); //echo "cn: " . self::$link . "<br>"; return (self::$link); } Quote Link to comment https://forums.phpfreaks.com/topic/198516-problem-with-multiple-mysql-calls-on-a-static-php-class/#findComment-1043732 Share on other sites More sharing options...
fenway Posted April 18, 2010 Share Posted April 18, 2010 This has to do with php's mysql functions, not the mysql server. Quote Link to comment https://forums.phpfreaks.com/topic/198516-problem-with-multiple-mysql-calls-on-a-static-php-class/#findComment-1044194 Share on other sites More sharing options...
Mchl Posted April 18, 2010 Share Posted April 18, 2010 It also indicates, that the query you run just before failed for some reason. Use mysql_error to find out. Quote Link to comment https://forums.phpfreaks.com/topic/198516-problem-with-multiple-mysql-calls-on-a-static-php-class/#findComment-1044203 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.