Forum Moderators: coopster

Message Too Old, No Replies

MySQL Errors - Resource ID

What are the resource IDs?

         

migthegreek

12:26 pm on May 29, 2009 (gmt 0)

10+ Year Member



I have noticed when I execute certain mysql functions, I often get a return of 'Resource id #0' where 0 is what seems to be a consistent number.

For example, the connection is Resource id #6 and when I have a SQL error, the query result returns Resource id #7, I think.

What I want to know is, what are these IDs, are they constant, and can I use them as the basis for helpful error reporting? For example, if it's Resource id #7, do I know for sure that it was a problem with executing the query?

I couldn't find an online list of all the types of resource IDs and what they mean.

mvaz

12:54 pm on May 29, 2009 (gmt 0)

10+ Year Member



welcome migthegreek!
You need to check what resource that you pass to mysql query. You could be passing something that gives out this error; moreover, without your code, it is hard for the experts here to figure out where it has gone wrong.

eelixduppy

2:09 pm on May 29, 2009 (gmt 0)



Some of the MySQL Functions return resources and that is what you are seeing. If you are trying to echo a resource variable to the browser you are going to see this string representation of it. Correct debugging for MySQL scripts would look something like the following, using the function mysql_error [php.net]().


$result = mysql_query($query) or die(mysql_error());

Try something like that and see if you can't spot your errors. Otherwise post the relevant code and we'll see what we can do.

migthegreek

2:27 pm on May 29, 2009 (gmt 0)

10+ Year Member



Sorry, I should've explained, I'm not actually having any problems with code. I am building a framework for an application, and have built an error reporting system. When there is a DB error, it goes to a specific error page with information about what has gone wrong.

I was wondering if I can use these resource IDs to know what very specific error has occurred, and display the appropriate error message and information about it.

The current system works fine, and I can establish whether there is a connection problem, database doesn't exist, query is malformed or invalid, etc. I was just wondering if I can streamline it.

eelixduppy

2:58 pm on May 29, 2009 (gmt 0)



As far as using the resource ID numbers for error handling I do not think that would be possible. The resource ID, I believe, is numbered according to the order that they are made. For example if you query twice, the first one could return a resource ID #4 while the second one would return a resource ID #5.

It seems that you are going to have to keep your current method of catching errors or find another way to do it. I don't see using the resource ID as a viable way to handle errors.

[edited by: eelixduppy at 3:10 pm (utc) on May 29, 2009]

migthegreek

3:08 pm on May 29, 2009 (gmt 0)

10+ Year Member



OK, that's not a problem, I was just wondering if the resource IDs would be useful.

Thanks.