SitePoint Sponsor

User Tag List

Results 1 to 21 of 21
  1. #1
    SitePoint Enthusiast
    Join Date
    May 2003
    Location
    Lincoln NE
    Posts
    58
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    what does Resource id #7 means?

    Hello,

    I tried to echo my select query to see what it looks like.

    PHP Code:
    $modify_qry mysql_query("SELECT * FROM $table WHERE pid=$pid");
    echo 
    $modify_qry 
    and here is what I got:
    Resource id #7
    what does this mean?
    all the variable in the select query are present. Thanks!

  2. #2
    Put your best practices away. The New Guy's Avatar
    Join Date
    Sep 2002
    Location
    Canada
    Posts
    2,087
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    try

    $modify_qry = mysql_query("SELECT * FROM '$table' WHERE pid='$pid'");
    echo
    $modify_qry ;
    "A nerd who gets contacts
    and a trendy hair cut is still a nerd"

    - Stephen Colbert on Apple Users

  3. #3
    SitePoint Addict Messiah's Avatar
    Join Date
    Jun 2001
    Location
    Bloomington, In.
    Posts
    216
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you want to echo your query, try it like this:

    PHP Code:
    $qry "SELECT * FROM $table WHERE pid=$pid";
    echo 
    $qry
    Messiah | Ink-Press: web publishing simplified!

  4. #4
    SitePoint Addict Messiah's Avatar
    Join Date
    Jun 2001
    Location
    Bloomington, In.
    Posts
    216
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The New Guy,

    Single quoting the vars isn't necessary and will return the same result. You can't echo the the result of an executed query directly and expect to see the query results. mysql_query returns a result id. Hence the output chafikb was getting.
    Messiah | Ink-Press: web publishing simplified!

  5. #5
    SitePoint Enthusiast
    Join Date
    May 2003
    Location
    Lincoln NE
    Posts
    58
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried the new guys method and got this error
    Error retrieving information from database!
    Error: You have an error in your SQL syntax near ''african' WHERE pid='1'' at line 1
    give me a sec to try Messiah's.


    Quote Originally Posted by Messiah
    The New Guy,

    Single quoting the vars isn't necessary and will return the same result. You can't echo the the result of an executed query directly and expect to see the query results. mysql_query returns a result id. Hence the output chafikb was getting.

  6. #6
    Put your best practices away. The New Guy's Avatar
    Join Date
    Sep 2002
    Location
    Canada
    Posts
    2,087
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Is the resource id a notice?

    Edit: Try taking the single quotes of the table name.
    "A nerd who gets contacts
    and a trendy hair cut is still a nerd"

    - Stephen Colbert on Apple Users

  7. #7
    chown linux:users\ /world Hartmann's Avatar
    Join Date
    Aug 2000
    Location
    Houston, TX, USA
    Posts
    6,455
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    Isn't the resource id a value in an array?

  8. #8
    Put your best practices away. The New Guy's Avatar
    Join Date
    Sep 2002
    Location
    Canada
    Posts
    2,087
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Yah it is, sorry, I havn't messed with php in almost 6 months now. I am very rusty. Though I get Resource ID 2 when trying to replicate the error .
    "A nerd who gets contacts
    and a trendy hair cut is still a nerd"

    - Stephen Colbert on Apple Users

  9. #9
    SitePoint Enthusiast
    Join Date
    May 2003
    Location
    Lincoln NE
    Posts
    58
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I got it to work... Thanks much for the help guys

  10. #10
    SitePoint Evangelist Daijoubu's Avatar
    Join Date
    Oct 2002
    Location
    Canada QC
    Posts
    454
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You have to mysq_fetch'it, the ressource id is just the query id (I think)
    Speed & scalability in mind...
    If you find my reply helpful, fell free to give me a point

  11. #11
    ********* Member website's Avatar
    Join Date
    Oct 2002
    Location
    Iceland
    Posts
    1,238
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Daijoubu
    You have to mysq_fetch'it, the ressource id is just the query id (I think)
    Yep, correct. You can't simply echo the result, it isn't in any... "form" (not an array/string etc., although you can make a multi dimensional array from it).
    - website

  12. #12
    SitePoint Evangelist Daijoubu's Avatar
    Join Date
    Oct 2002
    Location
    Canada QC
    Posts
    454
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Now, what's the difference between all the mysql_fetch_*?
    I always used mysql_fetch_array through a while loop... (That question sound newbie eh? )
    Speed & scalability in mind...
    If you find my reply helpful, fell free to give me a point

  13. #13
    ********* Member website's Avatar
    Join Date
    Oct 2002
    Location
    Iceland
    Posts
    1,238
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    mysql_fetch_row only returns array with numeric keys (0 meaning the first column you asked for in the query, 1 the second etc.)
    mysql_fetch_assoc only returns array with string hashes or what ever it is called, so it returns the name of the column, not the order.

    Example:
    PHP Code:
    $rslt mysql_query('SELECT colA, colB, colC FROM Table LIMIT 1');
    $row1 mysql_fetch_assoc($rslt);
    //lets say then that I didn't have the line above, will then not go to the next line, but just use the first.
    //while loop isn't needed since I have LIMIT 1
    $row2 mysql_fetch_row($rslt);
    //then $row1[0] = $row2['colA']; $row1[1] = $row2['colB'] and $row1[2] = $row2['colC'] 
    Hope you understand this...
    - website

  14. #14
    SitePoint Evangelist Daijoubu's Avatar
    Join Date
    Oct 2002
    Location
    Canada QC
    Posts
    454
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What would return print_r($row1) ?
    Going to make a little test script, thanks for your explanation
    The examples on php.net aren't that clear
    Speed & scalability in mind...
    If you find my reply helpful, fell free to give me a point

  15. #15
    ********* Member website's Avatar
    Join Date
    Oct 2002
    Location
    Iceland
    Posts
    1,238
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    print_r($row1) would return something like
    Code:
    Array( [0] => 'value of column A'
    [1] => 'value of column B'
    [2] => 'value of column C');
    if I remember the syntax of print_r correctly
    - website

  16. #16
    SitePoint Evangelist Daijoubu's Avatar
    Join Date
    Oct 2002
    Location
    Canada QC
    Posts
    454
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I see now..reference for the other newbies out there :
    Query I ran (from IPB):

    $query = mysql_query('SELECT macro_value, macro_replace FROM ibf_macro WHERE macro_set=5 LIMIT 1');

    mysql_fetch_assoc($result) / mysql_fetch_array($result, MYSQL_ASSOC)

    Returns:
    Code:
    Array
    (
    	[macro_value] => C_ON_CAT
    	[macro_replace] => New Posts
    )
    mysql_fetch_row($result) / mysql_fetch_array($result, MYSQL_NUM)
    Returns:
    Code:
    Array
    (
        [0] => C_ON_CAT
        [1] => New Posts
    )
    mysql_fetch_array($result, MYSQL_BOTH)
    Would return both:
    Code:
    Array
    (
        [0] => C_ON_CAT
        [macro_value] => C_ON_CAT
        [1] => New Posts
        [macro_replace] => New Posts
    )
    Now, what's faster? mysql_fetch_assoc($result) or mysql_fetch_array($result, MYSQL_ASSOC)?
    Speed & scalability in mind...
    If you find my reply helpful, fell free to give me a point

  17. #17
    ********* Member website's Avatar
    Join Date
    Oct 2002
    Location
    Iceland
    Posts
    1,238
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by PHP manual pages for mysql_fetch_assoc
    An important thing to note is that using mysql_fetch_assoc() is not significantly slower than using mysql_fetch_row(), while it provides a significant added value.
    and then again
    Quote Originally Posted by PHP manual pages for mysql_fetch_array
    An important thing to note is that using mysql_fetch_array() is not significantly slower than using mysql_fetch_row(), while it provides a significant added value
    So it seems that ordered from fastest to slowest it would be like this:
    mysql_fetch_row
    mysql_fetch_assoc
    mysql_fetch_array
    Although you could argue about the order of the last two I would say mysql_fetch_array is slower since it outputs more data.

    Then again the difference isn't enough to worry about
    - website

  18. #18
    SitePoint Evangelist Daijoubu's Avatar
    Join Date
    Oct 2002
    Location
    Canada QC
    Posts
    454
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Indeed, little faster
    Any comment on mysql_num_rows vs incrementing a variable ($rows['rows']++) vs count($rows)
    I made a little benchmark script but the results are various...

    ($rows is inside a while loop with mysql_fetch_assoc)
    Speed & scalability in mind...
    If you find my reply helpful, fell free to give me a point

  19. #19
    ********* Member website's Avatar
    Join Date
    Oct 2002
    Location
    Iceland
    Posts
    1,238
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well, I suppose mysql_num_rows is propably the best, I would be suprised if the php development team didn't always try to make functions faster then you could by actually creating it yourself . Another thing is that it makes much cleaner code, to use mysql_num_rows, and pretty and clean are often more important then having it a bit faster.
    - website

  20. #20
    SitePoint Evangelist Daijoubu's Avatar
    Join Date
    Oct 2002
    Location
    Canada QC
    Posts
    454
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, it's important for the size of the board i run
    Speed & scalability in mind...
    If you find my reply helpful, fell free to give me a point

  21. #21
    ********* Wizard silver trophy Cam's Avatar
    Join Date
    Aug 2002
    Location
    Burpengary, Australia
    Posts
    4,495
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    As it wasn't explicitly explained, a resource ID number is just that, the way PHP keeps track of resource data types. These include database connections, resultsets, file pointers, socket connections and others. It's a kind of abstract data type and can be checked for with is_resource().

    More information can be found here and here


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •