pps_dev Posted January 30, 2008 Share Posted January 30, 2008 Hello folks, I'm trying to return a resultset from MySQL and can't figure out why it is not working. My only thinking is that it is the way variables are passed around functions in PHP but I can't see why it would make a difference. Anyway: This is my little "do_mysql_select" function which I started using to return $result. function do_mysql_select($details,$table,$whereclause='',$orderby=''){ $dbconn = db_connect("mysql"); $query = prepare_sql_select($details,$table,$whereclause,$orderby); $result = mysql_query($query); f_mysql_close($dbconn); } However, if I then use it like $result = do_mysql_select("something","a_table"); The returned $result is "not a valid MySQL result resource" and so I cannot then use as I would like. The $query is being put together correctly and I can use the $result within the do_mysql_select function so the problem is in passing the $result back out of the function. Unless I am being stupid. Does anybody know why this is? Thanks in advance dev Link to comment https://forums.phpfreaks.com/topic/88537-help-with-odd-returning-mysql-results/ Share on other sites More sharing options...
PHP Monkeh Posted January 30, 2008 Share Posted January 30, 2008 You could add: $result = mysql_query($query) or die(mysql_error()); and see if it's generating any errors while trying to run the query (which I'm assuming it is). Does it work if you just use a normal query? Rather than your own function. Link to comment https://forums.phpfreaks.com/topic/88537-help-with-odd-returning-mysql-results/#findComment-453250 Share on other sites More sharing options...
laffin Posted January 30, 2008 Share Posted January 30, 2008 u may have to look at this function as well prepare_sql_select($details,$table,$whereclause,$orderby); Link to comment https://forums.phpfreaks.com/topic/88537-help-with-odd-returning-mysql-results/#findComment-453253 Share on other sites More sharing options...
pps_dev Posted January 30, 2008 Author Share Posted January 30, 2008 Right. The MySQL version has started working for some unknown reason. I followed PHP Monkeh's advice and tried my own SELECT statement and it worked, took that out and used my prepare_sql_select function again and that works now. I don't understand why but it does. Now though, I'm having the same problem with my MSSQL version of the function: function do_mssql_select($details,$table,$whereclause='',$orderby=''){ if ($dbconn = db_connect("mssql")){ // $query = prepare_sql_select($details,$table,$whereclause,$orderby); $query = "SELECT * FROM xx_table"; $result = mssql_query($query); f_mssql_close($dbconn); return $result; } } The only difference between the two functions now is the word "mssql" being used instead of "mysql", but the returned $result cannot be used to mssql_fetch_array from. If I fetch the array from within this function it returns the values expected: while ($rs = mssql_fetch_array($result,MSSQL_BOTH)){ echo $rs[0]."<BR>"; } Is there a difference in uses of MSSQL and MySQL resultsets? Most confused now. dev Link to comment https://forums.phpfreaks.com/topic/88537-help-with-odd-returning-mysql-results/#findComment-453259 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.