php参数化SQL查询特殊运算符

标签 php sql operators sql-injection parameterized-query

我刚好看到下面的构造参数化SQL查询的方式:

function select_user($uid)
{
    // what is '<<<'?  
    // I can't google any document about it
    // (or I don't know how to search symbol)

    $sqlStr = <<< SQL_STR

         SELECT * FROM user WHERE uid = ?

SQL_STR; // must put in the begin of the line
         // and it must match the word at the right hand side of '= <<<'

    // Code Igniter Database Class
    return $this->db->query($sqlStr, array($uid));
}

在这里重新表述我的问题:

  • 什么符号' <<< ' 是吗?
  • 我的同事说'SQL_STR ' 必须匹配,为什么?

最佳答案

Heredoc 用于定义字符串,通常是因为不必在整个字符串中转义引号,这与字符串文字不同。

来自Manual :

Heredoc text behaves just like a double-quoted string, without the double quotes. This means that quotes in a heredoc do not need to be escaped, but the escape codes listed above can still be used. Variables are expanded, but the same care must be taken when expressing complex variables inside a heredoc as with strings.

$str = <<<EOD
Example of string
spanning multiple lines
using heredoc syntax.
EOD;

关于php参数化SQL查询特殊运算符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13492464/

相关文章:

php - 将 mysql 结果输出为形式的数组(列名 => 列名的可能值)

sql - hive 查询 Json 喜欢或等于的地方

function - mathematica中有没有可以用来定义输入类型的函数头?

PHP MySQL 插入查询,如果已经存在则不会插入

php - 将包含 mysql 函数的 mysql 查询传递给 PHP mysql_query

php - cal_days_in_month () 函数不起作用

sql - 从一个表批量插入到服务器上的另一个表

mysql - 从mysql数据库获取最大计数

java - 当我期望代码简单地打印 "Error"时,为什么我的代码会抛出 ArithmeticException ?

c++ - 使用关系运算符比较指针是什么意思?