简体   繁体   中英

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

   $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. 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'] .

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. 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 != b & c

Whereas this is evaluated as 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

I think you need to look at the query_field function to figure out what that's doing. 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.)

What is $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. 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 (!). That seems the most likely explanation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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