473,490 Members | 2,737 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

suplied argument not valid mysql sql resource

bilibytes
128 New Member
hi,
i tried to create sort of a db abstraction layer in order to be able to change of database (Mysql | oracle | pg |...).

i implemented that on a obejct oriented way.

i made a sql factory in PHP which simply instanciate classes whose methods wrap the php normal sql functions like mysql_query() mysql_num_rows() pg_query()...
one of these methods is num_rows()

i implemented it this way:
Expand|Select|Wrap|Line Numbers
  1. public function num_rows($result)
  2. {
  3.     return mysql_num_rows($result);
  4. }
  5.  
the problem is it will generate a mysql error:
mysql_num_rows(): supplied argument is not a valid MySQL result resource in ...

so i thought it could be because i'm not passing the argument as a reference so i changed that to:

Expand|Select|Wrap|Line Numbers
  1. public function num_rows(&$result)
  2. {
  3.     return mysql_num_rows($result);
  4. }
but it still returns that error.

how should that be done?

do you have any suggestions?

by the way how can i know if an insertion succeed, without the "or die(mysql_error)"?

please let me know

thank you!

best regards

bilibytes
Dec 10 '08 #1
2 2191
code green
1,726 Recognized Expert Top Contributor
Echo out the value of $result.
It should be something like #2.
If not, as is almost certainly the case the result resource is not in $result.
We would need to see more code to repair this.

Also a reminder this only works with SELECT queries

On a design point I have a similar class.
But because the result resource may be used within a number of methods
I place it in a class member variable

//Private members
private $result;

function xxxxxx()
$this->result = mysql_query()

function xxx()
mysql_num_rows($this->result)
Dec 10 '08 #2
bilibytes
128 New Member
Thank you for your time.

but i managed to solve it, it was a problem of the mysql_query() wrapper.

Expand|Select|Wrap|Line Numbers
  1. public function query($sql_code)
  2. {
  3.     return mysql_query($sql_code, $this->link) or die(mysql_error());
  4. }
i put the or die(mysql_error()) while debugging and that was causing all the problems.
What i still don't understand is why it happens.. what does it return when i put or die(mysql_error())
mysql_error() should not get triggered as when i don't put the or die()... the query works perfectly.

ahhh maybe it returns a boolean?

like: "return the evaluation of these two conditions, if one is true retrun true?"

i think that may be the reason

best regards
Dec 10 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

12
28449
by: Burton Figg | last post by:
Before I get in trouble, I have searched extensively for this one, in the PHP Docs, online etc. I have a simple page: <?php $un="jim"; $pw="jim"; $db="localhost";
6
4639
by: aa | last post by:
I use the following fragment of code to output datf from MySQL: ====================================================== $chan = mysql_connect ($db_host, $username, $password); mysql_select_db...
4
7821
by: Ryanlawrence1 | last post by:
Heya, I get these 2 errors: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/themepar/public_html/changepass.php on line 20 You have not entered all the...
2
16894
by: techjohnny | last post by:
Error: Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/jplane/certcent/phpweb/quiz/index.php on line 20 Warning: mysql_num_rows(): supplied argument is...
1
2688
by: lsmamadele | last post by:
I am getting the following error messages in my search: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/mamadele/public_html/BESTPLAYS/search.php on...
4
2215
by: jpenney | last post by:
Hi, I gotta dum kweschin. Here's muh code: class dbServer{ ... public function &executeDBCOMMAND($SQL=";"){
11
3573
by: Breana | last post by:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/breana/public_html/category.php on line 88 ------------------------------------------- It does this...
5
2346
by: Mubs | last post by:
Hi, I 'am trying to connect my sql database with my webpage for users log in. i have got this script so far but i keep getting the following error message which i cannot figure out.. could any1...
4
5017
by: fisherd | last post by:
When i run this code, i keep getting this message; Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\wamp\www\checklogin.php on line 26 i use this code to...
0
7112
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6974
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7183
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6852
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7356
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5448
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4878
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4573
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
1
628
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.