AAC-Bob Posted November 15, 2013 Share Posted November 15, 2013 I am attempting to change some php code to mysqli. I'm not a skilled programmer and am running into some query problems. Here is the Existing code; Here is the Existing code; <?php $link = mysql_connect($config['DB_Host'], $config['DB_User'], $config['DB_Passwd']) or die('Cannot connect to the database'); mysql_select_db($config['DB_Name'],$link) or die('Cannot select the database'); parse_str(str_replace(':', '&', $_COOKIE['UserSettings']),$userInfo); $MemberID = $userInfo["MemberID"]; $query = "SELECT PersonID FROM `membershipperson` where MembershipID = ".$MemberID; $result = mysql_query($query) or die ("Errant Query: ".$query); $record = mysql_fetch_array($result); $personID = $record["PersonID"]; # additional code below ?> New Code <?php include ("mySqli_conn.php"); $result = $link->query($sql)or die('Cannot select the database'); parse_str(str_replace(':', '&', $_COOKIE['UserSettings']),$userInfo); $MemberID = $userInfo["MemberID"]; $sql = "SELECT PersonID FROM `membershipperson` where MembershipID = ".$MemberID; $result = $link->query($sql)or die ("Errant Query: ".$query); $result->fetch_array($result); $personID = $record["PersonID"]; ?> Error Warning: mysqli::query() [mysqli.query]: Empty query in /~/position.php on line 6 Cannot select the database Thanks, Bob C Quote Link to comment https://forums.phpfreaks.com/topic/283935-changing-code-to-mysqli/ Share on other sites More sharing options...
Ch0cu3r Posted November 15, 2013 Share Posted November 15, 2013 (edited) It because of this here <?php include ("mySqli_conn.php"); $result = $link->query($sql)or die('Cannot select the database'); What query are you trying to run here. Basically $sql is either empty or not defined. So you are getting the Empty query error message. Is this for selecting the database to use? If its you tell mysqli what database to use when you connect. $link = new mysqli('hostname', 'username', 'password', 'database name'); // object // OR $link = mysqli_connect('hostname', 'username', 'password', 'database name'); // procedural Edited November 15, 2013 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/283935-changing-code-to-mysqli/#findComment-1458423 Share on other sites More sharing options...
AAC-Bob Posted November 15, 2013 Author Share Posted November 15, 2013 It because of this here <?phpinclude ("mySqli_conn.php");$result = $link->query($sql)or die('Cannot select the database');What query are you trying to run here. Basically $sql is either empty or not defined. So you are getting the Empty query error message. Is this for selecting the database to use? If its you tell mysqli what database to use when you connect. $link = new mysqli('hostname', 'username', 'password', 'database name'); // object// OR$link = mysqli_connect('hostname', 'username', 'password', 'database name'); // procedural I use the include ("mySqli_conn.php"); for all my php database mysqli connections. I have 4 other pages using this common file that work just fine. If this is the problem then I am confused. Bob Quote Link to comment https://forums.phpfreaks.com/topic/283935-changing-code-to-mysqli/#findComment-1458425 Share on other sites More sharing options...
Ch0cu3r Posted November 15, 2013 Share Posted November 15, 2013 The include is not the issue. Its this $result = $link->query($sql)or die('Cannot select the database'); That is what is causing the error. Delete it. Quote Link to comment https://forums.phpfreaks.com/topic/283935-changing-code-to-mysqli/#findComment-1458429 Share on other sites More sharing options...
AAC-Bob Posted November 15, 2013 Author Share Posted November 15, 2013 (edited) The include is not the issue. Its this $result = $link->query($sql)or die('Cannot select the database');That is what is causing the error. Delete it. OK I removed it and error gone, TNX, Edited November 15, 2013 by AAC-Bob Quote Link to comment https://forums.phpfreaks.com/topic/283935-changing-code-to-mysqli/#findComment-1458430 Share on other sites More sharing options...
Ch0cu3r Posted November 15, 2013 Share Posted November 15, 2013 (edited) $result->fetch_array($result); needs to be $record = $result->fetch_array(MYSQLI_ASSOC); Read the manual on mysqli fetch_array http://us2.php.net/mysqli_fetch_array Edited November 15, 2013 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/283935-changing-code-to-mysqli/#findComment-1458433 Share on other sites More sharing options...
AAC-Bob Posted November 15, 2013 Author Share Posted November 15, 2013 (edited) Hi Ch0cu3r, I went to the link and resolved the problem. Thank you. OK now one more I can't seam to solve; original; while($row2 = mysql_fetch_array($results2)) tried; while($row2 = $result2->fetch_array()) error: Warning: mysql_fetch_array() expects parameter 1 to be resource, null given Bob Edited November 15, 2013 by AAC-Bob Quote Link to comment https://forums.phpfreaks.com/topic/283935-changing-code-to-mysqli/#findComment-1458443 Share on other sites More sharing options...
mac_gyver Posted November 16, 2013 Share Posted November 16, 2013 since your error message is still for an old mysql_ function, you either didn't save the changes to the file or the error is from some other line in your code. Quote Link to comment https://forums.phpfreaks.com/topic/283935-changing-code-to-mysqli/#findComment-1458583 Share on other sites More sharing options...
cyberRobot Posted November 17, 2013 Share Posted November 17, 2013 $result->fetch_array($result); needs to be $record = $result->fetch_array(MYSQLI_ASSOC); Read the manual on mysqli fetch_array http://us2.php.net/mysqli_fetch_array You could also use $record = $result->fetch_assoc(); Quote Link to comment https://forums.phpfreaks.com/topic/283935-changing-code-to-mysqli/#findComment-1458701 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.