Jump to content


Photo

MySQL Query not Returning as a Resource


  • Please log in to reply
3 replies to this topic

#1 vnought

vnought
  • Members
  • PipPipPip
  • Advanced Member
  • 179 posts
  • LocationCanada

Posted 09 July 2006 - 02:13 PM

Hey all,

I'm having a little problem with PHP and its mysql commands, I've set up apache 2.2 with php 5, installed coldfusion on it, and datasource access worked fine. Then I went over to PHP, and I tried to recreate the exact same thing as is present in the CFML version... So far so good.

And then I get to a point where mysql_* commands beyond mysql_pconnect/connect get me a 'not a valid resource' error!

I've done some tinkering and it turns out that the mysql_* commands (with exception to the connect and pconnect functions) return a boolean rather then a resource!

	$db = mysql_pconnect( $host, $user, $pass ) or die(mysql_error());
	mysql_select_db( 'dbinventory', $db );

	$q_INV = "SELECT * FROM tblMedia";

	# Returns a boolean, but I want it to return a resource!
	$rs_INV = mysql_query( $q_INV, $db );
	$rs_INV_rows = mysql_num_rows( $rs_INV );
	$rs_INV_cols = mysql_num_fields( $rs_INV );

Simple no? But, as I tried our rs_INV with the is_resource and is_bool, it comes out boolean regardless of what I try.

Any suggestions?

#2 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 09 July 2006 - 03:03 PM

Try putting
or die(mysql_error())
after the mysql_query so it becomes
$rs_INV = mysql_query( $q_INV, $db ) or die(mysql_error());
and see if it returnss any error.

#3 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 10 July 2006 - 01:00 AM

Agreed... that bool is probably FALSE, indicating an error.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#4 vnought

vnought
  • Members
  • PipPipPip
  • Advanced Member
  • 179 posts
  • LocationCanada

Posted 10 July 2006 - 10:32 AM

Try putting

or die(mysql_error())
after the mysql_query so it becomes
$rs_INV = mysql_query( $q_INV, $db ) or die(mysql_error());
and see if it returnss any error.


Thanks Daniel, silly that I didn't think of that sooner! But yea, cleared up the problem and I fixed it (user wasn't permitted to access remotely).

Thanks!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users