UrbanDweller Posted March 31, 2012 Share Posted March 31, 2012 Hey, I found some code online that references a bunch of sql commands in there own functions that can be called from a require_once(), All the ones I have tried work expect mysql_query when its called it returns this error: Warning: mysql_result() expects parameter 1 to be resource, boolean given in But once i paste the mysql_query into the main script it works fines. code below is mine and the online script. Webcode: $sql = "SELECT cat_id, cat_parent_id, cat_name, cat_description, cat_image FROM tbl_category WHERE cat_parent_id = $catId ORDER BY cat_name"; /* Don't know what getPagingQuery does and couldnt find any reference to it so i removed it and replaced with simple query in my own code */ $result = dbQuery(getPagingQuery($sql, $rowsPerPage)); My Code: $sql = "SELECT cat_id, cat_parent_id, cat_name, cat_description, cat_image FROM tbl_category WHERE cat_parent_id = $catId ORDER BY cat_name"; $result = dbQuery($sql); Include file: $dbHost = "localhost"; //SQL Server $dbUser = "root"; // Database username $dbPass = ""; // Database password $dbName = "lh_shop"; // Database name $sqlCon = mysql_connect($dbHost, $dbUser, $dbPass) or die ('MYSQL connection Failed. ' . mysql_error()); mysql_select_db($dbName) or die('Cannot select database. ' . mysql_error()); // Database query functions function dbQuery($sql) { return mysql_query($sql) or die('Query failed. ' . mysql_error()); } Thanks, I really hope someone has had this issue Quote Link to comment https://forums.phpfreaks.com/topic/260055-boolean-error-calling-external-mysql_query/ Share on other sites More sharing options...
gizmola Posted March 31, 2012 Share Posted March 31, 2012 The error is telling you that whatever query was executed generated an error rather than a valid result set. Quote Link to comment https://forums.phpfreaks.com/topic/260055-boolean-error-calling-external-mysql_query/#findComment-1332964 Share on other sites More sharing options...
UrbanDweller Posted March 31, 2012 Author Share Posted March 31, 2012 But why is it that if i call the query not from the include but inside the main file the same code works. Quote Link to comment https://forums.phpfreaks.com/topic/260055-boolean-error-calling-external-mysql_query/#findComment-1332967 Share on other sites More sharing options...
gizmola Posted April 1, 2012 Share Posted April 1, 2012 But why is it that if i call the query not from the include but inside the main file the same code works. I'm simply relating to you what the error message indicates. You didn't provide the code that actually calls the error. If this is code you didn't write yourself, as it seems you indicated in your original message, you'll have to learn enough about it to actually debug the problem. Quote Link to comment https://forums.phpfreaks.com/topic/260055-boolean-error-calling-external-mysql_query/#findComment-1333233 Share on other sites More sharing options...
UrbanDweller Posted April 2, 2012 Author Share Posted April 2, 2012 Bugging and testing finally found a way to work the return function needed to me edited Quote Link to comment https://forums.phpfreaks.com/topic/260055-boolean-error-calling-external-mysql_query/#findComment-1333473 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.