Jump to content

Recommended Posts

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

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.

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.