简体   繁体   English

以下PHP代码中的“=!”是什么意思?

[英]What does “= !” in the following PHP code mean?

When i run the sql script and substitute it with a numbers it return empty or null 当我运行sql脚本并用数字替换它时,它返回空或null

   $order_f = $dbs->query_field("SELECT order_id FROM orders WHERE order_center_id = !", $record['cust_id']);

What does the = ! 什么=! stand for? 代表? Is this not equal? 这不相等吗?

It's not an operator at all! 它根本不是运营商!

In your case it seems that the query_field() method that's provided by your database object (which I think is based on MDB2 ) provides some kind of prepared statement, where exclamation marks are used for place holders. 在你的情况下,似乎你的数据库对象(我认为它基于MDB2 )提供的query_field()方法提供了某种预备语句,其中感叹号用于占位符。 I'm imagining that the following query is executed based on your code: 我想是根据你的代码执行以下查询:

SELECT order_id FROM orders WHERE order_center_id = 123

Where 123 is the value of $record['cust_id'] . 其中123$record['cust_id']

Old answer 老答案

In your case != (or <> ) could be the same as =! 在你的情况下!= (或<>可能=!相同=! (or = NOT(...) ), because "not equal to" might be considered the same as "equal to inverse of", but only for boolean value logic. (或= NOT(...) ),因为“不等于”可能被认为与“等于倒数”相同,但仅适用于布尔值逻辑。 It will not work when you compare strings. 比较字符串时它不起作用。

Also, there's a difference in operator precedence : 此外, 运营商优先级有所不同:

a = !b & c

This is evaluated as a = NOT(b) & c . 这被评估为a = NOT(b) & c

a != b & c

Whereas this is evaluated as a = NOT(b & c) . 而这被评估为a = NOT(b & c)

Q: What does the = ! 问:什么=! stand for? 代表? Is this not equal? 这不相等吗?

No. A not equals comparator would be foo != bar or foo <> bar 不,A等于比较器就是foo != barfoo <> bar

I think you need to look at the query_field function to figure out what that's doing. 我认为你需要查看query_field函数来弄清楚它在做什么。 It looks like the query is intended to do an equals comparison, and that exclamation point is a placeholder. 看起来该查询旨在进行等于比较,并且该感叹号是占位符。 (I'm not familiar with that query_field function; it doesn't look like a mysql_, mysqli_ or a PDO function, at least, that I've ever seen.) (我不熟悉query_field函数;它看起来不像mysql_,mysqli_或PDO函数,至少,我见过。)

What is $dbs ? 什么是$dbs What kind of object is that? 这是什么样的对象? I bet that's where this method is defined. 我敢打赌,这就是定义这种方法的地方。

I suspect someone has added a layer, on top of mysql interface, to pseudo-support paramaterized queries. 我怀疑有人在mysql接口之上添加了一个伪支持参数化查询的层。 Likely, that second argument to the function gets run through mysql_real_escape_string, before it's included in the SQL text, replacing the bang (!). 可能,函数的第二个参数通过mysql_real_escape_string运行,在它包含在SQL文本中之前,替换了bang(!)。 That seems the most likely explanation. 这似乎是最可能的解释。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM