duandan4680 2013-06-12 20:07
浏览 39
已采纳

PHP MySql双引号比单引号

I was reading a book about PHP and saw this code for inserting records. I do not understand a specific expression in the default case of the ternary operator. More specifically:

"'$v',"

Did the author make a mistake using single quotes (') and what he really meant were the backticks(`) to quote a soecial mysql expression? Why would you use single quotes and then double quotes on a variable?

According to the mysql documentation :

"The identifier quote character is the backtick (“`”): " http://dev.mysql.com/doc/refman/5.0/en/identifiers.html

public function insertRecords($table, $data){
    //setup some variables for fields and values
    $fields = "";
    $values = "";

    //populate them
    foreach($data as $f => $v){
        $fields .= "`$f`,";
        $values .= (is_numeric($v) && (intval($v) == $v)) ? $v . "," : "'$v',";
    }
}
  • 写回答

4条回答 默认 最新

  • dounai1986 2013-06-12 20:13
    关注

    double quotes signify that it's a string and the single quotes are part of a string. inside double quotes variables are evaluated so the string will contain the value of the variable 'vValue' not '$v'

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

报告相同问题?

悬赏问题

  • ¥15 eda:门禁系统设计
  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页
  • ¥15 376.1电表主站通信协议下发指令全被否认问题
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥15 复杂网络,变滞后传递熵,FDA
  • ¥20 csv格式数据集预处理及模型选择
  • ¥15 部分网页页面无法显示!
  • ¥15 怎样解决power bi 中设置管理聚合,详细信息表和详细信息列显示灰色,而不能选择相应的内容呢?
  • ¥15 QTOF MSE数据分析
  • ¥15 平板录音机录音问题解决