#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2010
    Posts
    26
    Rep Power
    0

    Sqlsrv_fetch_array


    OMG i'm gonna freak out... What am i missing.
    I have a table that looks like this:
    ID | fName | lName | about
    --------------------------------
    1 | Bob | Hope | Cool Guy

    Simple right:
    here is code for my select:

    PHP Code:
    $dbSearch "SELECT * FROM dbo.person";

    /*
    connection here -> yes its good
    */
    $stmnt sqlsrv_query$conn$dbSearch);
    if(
    $stmnt === false
    {
    print 
    errors blah blah
    }
    while( 
    $row sqlsrv_fetch_array($stmntSQLSRV_FETCH_ASSOC))
    {
    echo(
    $row['fName'].", ".$row['lName'].", ".$row['about']);


    I am getting nothing returned. It's like the array doesn't contain anything.

    what am i doing wrong?

    Thanks,
    dogdaynoon
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2010
    Posts
    26
    Rep Power
    0
    This seems like it should be something very simple.
    I am running mssql express 2012 on a virtual ms server 2008 r2 machine locally.
    I have created a very simple table and query. VERY SIMPLE
    the table is designed as above.
    I am using a new query now.
    SELECT fName, lName, about FROM dbo.person WHERE ID=7
    Yes i verified that the ID was 7.
    I am connecting to the server via the host machine, Google Chrome and the user is NT AUTHORITY\IUSR. Yes this user has rights to the db.

    Connection works, statment works but the fetch_array is returning nothing...
  4. #3
  5. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,692
    Rep Power
    6351
    Are you SURE the statement works? var_dump everything every step of the way and see if it's all what you expect. Turn error_reporting all the way up and see if there's any warnings that could be giving you clues.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2010
    Posts
    26
    Rep Power
    0
    well i just ran everything with var_dump and error_reporting is on with E_ALL set.

    nothing showing bad.
    everything just screws up at the sqlsrv_fetch_array().
    Returns NULL.
    It looks like the select is just not finding the data...
    did i write it completely wrong?

    Here:
    if i have the following table named boyOrGirl in a mssql db
    Code:
    ID | name  | sex
    -----------------
    1  | bob     | f
    and i want to select bob and his sex from this db isn't this the right statment?
    Code:
    SELECT name, sex FROM dbo.boyOrGirl WHERE name='bob'
  8. #5
  9. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,692
    Rep Power
    6351
    SQLSRV_FETCH_ARRAY is not a valid constant. You want SQLSRV_FETCH_ASSOC
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2010
    Posts
    26
    Rep Power
    0
    Originally Posted by ManiacDan
    SQLSRV_FETCH_ARRAY is not a valid constant. You want SQLSRV_FETCH_ASSOC
    Thanks, Yeah that was a typo on the forum the code is correct i changed my original post to reflect this.

    Sorry.

    Comments on this post

    • ManiacDan disagrees : Unbelievable
  12. #7
  13. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,692
    Rep Power
    6351
    I don't debug theoretical code. Could you fix my car if I drew you a picture of it?

    Comments on this post

    • DonR agrees : oh my, this sure gave me a good laugh :p
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.

IMN logo majestic logo threadwatch logo seochat tools logo