dpi96151 2012-01-02 19:27
浏览 189
已采纳

我在哪里需要在我的MYSQL查询中使用反引号或引号?

I am trying to run the following query, but I am not sure if my 's should be `s or not, $form_id = the record's column , $user_id is the primary key of the record called cf_id .

$querydate is going to be echo'd later on in the script, as it pulls the date from the record that equals to $form_id and $user_id .

$querydate = mysql_query("SELECT '$form_id' FROM email_history WHERE cf_id = '$user_id'") or die(mysql_error());

EDIT >>>>>>

After trying some of the solutions below, it seems to work ok, but instead of getting the date stored under the form name, I am getting this echo'd instead, so im not sure whats happening now : :Resource id #120 :Resource id #121 :Resource id #122 :Resource id #123

The table is setup like the followng:

[USER_ID] [FORM_ID1212212]  [FORM_ID1212112]  
 [1]      [2-1-2012]        [2-1-2012]       
 [2]      [1-1-2012]        [1-1-2012]       
  • 写回答

3条回答 默认 最新

  • douzhang1955 2012-01-02 19:30
    关注

    You use backticks (`) for table and column names, single quotes (') for strings.

    $querydate = mysql_query("SELECT `$form_id` FROM email_history WHERE cf_id = '$user_id'"); 
    

    Backticks are only needed when your table name or column name is a MySQL reserved word... best practise is to avoid reserved words

    But also consider switching to PDO and using prepared statements, or at least to mysqli rather than mysql

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥50 cocos2d-x lua 在mac上接入lua protobuf?
  • ¥15 es 7.17.20版本生成时间戳
  • ¥15 wpf dategrid表头排序图标自定义
  • ¥15 xshell无法连接提示ssh服务器拒绝密码
  • ¥15 AT89C52单片机C语言关于串口通信的位操作
  • ¥20 需要步骤截图(标签-服务器|关键词-map)
  • ¥50 gki vendor hook
  • ¥15 灰狼算法和蚁群算法如何结合
  • ¥15 写一个利用ESP32自带按键和LED控制的录像代码
  • ¥20 stm32f103,hal库 hal_usart_receive函数接收不到数据。