WordPress.org

Ready to get started?Download WordPress

Forums

Random question about grave accent ` in SQL (7 posts)

  1. toxinhead
    Member
    Posted 1 year ago #

    How come this doesn't work without grave accents but when i put them in it does?
    $wpdb->get_results("SELECT * FROM Tlogin WHERE key = 'heyy'");

    Im sure i have executed SQL commands without them in the past?

  2. andrewmills
    Member
    Posted 1 year ago #

    The SQL WHERE clause requires the quotes for text values, but not for numeric values.

    I'd guess all your key values in the past have been numeric, but this may be the first time your key value has been text?

  3. toxinhead
    Member
    Posted 1 year ago #

    Sorry i am meaning "backticks" -> `

    They are around the Tlogin, and key
    Thanks

  4. andrewmills
    Member
    Posted 1 year ago #

    Just to make sure I'm understanding correctly-- are you saying you have to put backticks around both the table name and the column name in your SQL query in order to make it work?

  5. toxinhead
    Member
    Posted 1 year ago #

    Yeah exactly, just going over my old code again, i never had it. :)

  6. andrewmills
    Member
    Posted 1 year ago #

    Okay, taking a wild guess on this, but . . . if get_results is invoking methods of the wpdb object, and it has to pass table names and column names into parameters for those methods . . . maybe then you need the backticks to get those names passed as if they were string literals?

    Like I said, I'm guessing-- but I'm making that guess based on examples I'm seeing in the wpdb class reference. They seem to use variables instead of literal table names in some of the examples.

    Or maybe there's some new code in the get_results that is doing prepare and/or sanitation on the parameters before performing the query?

  7. toxinhead
    Member
    Posted 1 year ago #

    Yea i think so too!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.