SQL query help (mysql database)

6 replies
Hey guys,
My background is ASP/MSSQL, so I'm a bit out of my depths with this one, and would certainly appreciate some help.

Can someone please tell me why this keeps throwing an error message?

$r2=query_wrapper("SELECT * FROM tblphotos WHERE tblph_shareID = ?", $share_ID " ORDER BY tblph_shareID DESC LIMIT 1");
#database #mysql #query #sql
  • Profile picture of the author Russell Mark
    Hi John,

    Is ?", $share_ID " ASP specific?

    I thought in ASP you just need + to concat strings, like:

    $r2=query_wrapper("SELECT * FROM tblphotos WHERE tblph_shareID = " + $share_ID + " ORDER BY tblph_shareID DESC LIMIT 1");
    {{ DiscussionBoard.errors[7968694].message }}
  • Profile picture of the author oldschoolwarrior
    Providing the actual "error message" would help alot.

    It depends on what the query_wrapper uses to query a database.

    With the ?, it looks like its using mysqli ...

    If your trying to bind parameters, your way off.

    PHP: mysqli_stmt::bind_param - Manual
    {{ DiscussionBoard.errors[7969515].message }}
  • Profile picture of the author Lanii
    Try this

    $r2=query_wrapper("SELECT * FROM tblphotos WHERE tblph_shareID="'. $share_ID.'" ORDER BY tblph_shareID DESC LIMIT 1");

    Not sure why there was "," before $share_ID but add it there if you think its required.
    {{ DiscussionBoard.errors[7969742].message }}
  • Profile picture of the author FirstSocialApps
    Not sure what the ? is for. Though I dont code in ASP the SQL should be the same. Are you looking for wildcard (%) ?


    $r2=query_wrapper("SELECT * FROM tblphotos WHERE tblph_shareID LIKE '%$share_ID ' ORDER BY tblph_shareID DESC LIMIT 1");
    {{ DiscussionBoard.errors[7970745].message }}
  • Profile picture of the author WebCure.in
    Originally Posted by John Romaine View Post


    Code:
    =query_wrapper("SELECT * FROM tblphotos WHERE tblph_shareID = ?",  " ORDER BY tblph_shareID DESC LIMIT 1");
    You have Written only LIMIT 1, in the end. Whereas, it should be LIMIT 0,1. Althought, Limit 1 would work well in MySQL. Some Databases Might Have Problems. Also, you have quotes at the wrong placed.

    So, your complete query will look like

    Code:
    =query_wrapper("SELECT * FROM tblphotos WHERE tblph_shareID = ? ,  ORDER BY tblph_shareID DESC LIMIT 0,1");
    {{ DiscussionBoard.errors[7971896].message }}
  • Profile picture of the author psvent
    What does "query_wrapper" do? Does just quote the SQL (to prevent injects?) or can you use it for query formatting?

    Maybe it can do something like this:

    Code:
    =query_wrapper("SELECT * FROM tblphotos WHERE tblph_shareID = ? ORDER BY tblph_shareID DESC LIMIT 1",  share_ID);
    But would have to know what query_wrapper does and what arguments it takes.
    {{ DiscussionBoard.errors[7974691].message }}

Trending Topics