Custom Fields
Re-Envisioned
Support MB Relationships Error SQL when use in the query the fields from or to in table mb_relationships

  • Creator
    Topic
  • #14878
    Resolved proyectohappyweb@gmail.com
    Participant

    Hello,

    I have the table mb_relationships created, and if I try to make a query by sql, if I use the fields from or to I have a error:

    If I use the field ID or the field type, the search is ok:
    ok-> $resultado = $wpdb->get_row($wpdb->prepare(“SELECT * FROM $table WHERE type = ‘opinion_to_atraccion'”));
    ok-> $resultado = $wpdb->get_row($wpdb->prepare(“SELECT * FROM $table WHERE ID = ’22′”) );

    But if in the query I use from or to, is a error..Maybe this two words have a conflict with the wordpress database?
    Error-> $resultado = $wpdb->get_row($wpdb->prepare(“SELECT * FROM $table WHERE from = $ID”));
    Error en la base de datos de WordPress: [You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ‘from = 1635’ at line 1]

    Error-> $resultado = $wpdb->get_row($wpdb->prepare(“SELECT to FROM $table WHERE from = $ID”));
    Error en la base de datos de WordPress: [You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ‘to FROM w47fa_mb_relationships WHERE from = 1635’ at line 1]
    SELECT to FROM w47fa_mb_relationships WHERE from = 1635

    Thanks,
    Sergio

Viewing 2 replies - 1 through 2 (of 2 total)
  • Author
    Replies
  • #14883
    Anh Tran
    Keymaster

    Hi Sergio,

    The problem is from is a reserved keyword for MySQL. You can’t use it directly in your SQL. To get over it, you need to put it in back ticks (`). Here is the modified SQL:

    https://pastebin.com/d8RUsspx

    (Can’t post the SQL here because back ticks are used to insert code in this forum)

    #14885

    Perfect!!! It run well!!!
    Many thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.