backtick和单引号之间有什么区别?我可以在上面的查询中使用IF语句吗? [英] What are the differences between backtick and single quote? Can I use IF statement in a query as above?
问题描述
在代码指示器手册中,写下以下内容。
$ this-> db-> select()接受一个
可选的第二个参数。如果将
设置为FALSE,CodeIgniter不会尝试
来保护您的字段或表名称
与反引号。如果
需要复合select语句,这将非常有用。
$this->db->select() accepts an optional second parameter. If you set it to FALSE, CodeIgniter will not try to protect your field or table names with backticks. This is useful if you need a compound select statement.
$this->db->select('(SELECT SUM(payments.amount) FROM payments
WHERE payments.invoice_id=4) AS amount_paid', FALSE);
$query = $this->db->get('mytable');
...
我有以下代码 CI应用程式之一。
$this->db->select('slug, type,
IF(`value` = "", `default`, `value`) as `value`', FALSE);
Q1。返回引号和单引号之间的区别是什么?
Q1. What are the differences between backtick ` and single quote '?
Q2。我可以在上面的查询中使用IF语句吗?
Q2. Can I use IF statement in a query as above?
Q3。这是什么意思?
Q3. What does this mean?
IF(`value` = "", `default`, `value`) as `value`
推荐答案
-
MySQL,反引号引用名称,而单引号创建字符串。如果你有一个名为
的列,选择
,当使用没有反引号的名称时,MySQL会抛出一个语法错误,例如SELECT select FROM foo $
In MySQL, backticks quote names, while single quotes create strings. If you have a column called
select
, MySQL would throw an syntax error when using this name without backticks -- like inSELECT select FROM foo
-- as it would interpret it as keyword which may not occur there.
可以使用此IF 函数作为SELECT语句中的列规范。请参阅 MySQL参考。
This IF function can be used as a column specification in SELECT statements. See the MySQL reference.
此函数返回默认
列中的值,如果 value
是空字符串。否则返回 value
本身的值。结果将被调用 value
。有关详细信息,请参见 MySQL参考。 / p>
This function returns the value from the default
column, if value
is the empty string. Else it returns the value from value
itself. The result will be called value
. See the MySQL reference for details.
这篇关于backtick和单引号之间有什么区别?我可以在上面的查询中使用IF语句吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!