What are all these SQL statements in Laravel?

I was browsing the Laravel source code, and I found many SQL statements for Eloquent, and I was wondering which ones and how to use them.

Unfortunately, I could not find any documentation.

Here are the operators I found in vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php :

 protected $operators = [ '=', '<', '>', '<=', '>=', '<>', '!=', 'like', 'like binary', 'not like', 'between', 'ilike', '&', '|', '^', '<<', '>>', 'rlike', 'regexp', 'not regexp', '~', '~*', '!~', '!~*', 'similar to', 'not similar to', ]; 

And there I do not understand a bunch of them. For example: & , | , ^ , << , >> , ~ , ~* !~ !~* .

Can someone show me an example of how they can be used?

thanks

+5
source share
3 answers

As other commentators note, these are bitwise operators. PHP bitwise operators are described here: http://php.net/manual/en/language.operators.bitwise.php

<strong> Examples

& is bitwise AND .

The bitwise AND takes two binary representations of equal length and performs the logical AND operation on each pair of the corresponding bit, by multiplying them. Thus, if both bits in the compared position are 1, the bit in the resulting binary representation is 1 (1 × 1 = 1); otherwise the result is 0 (1 × 0 = 0 and 0 × 0 = 0)

10 and 10 = 10 (all decimal representations). How? 10 is 1010 binary.

  1010 and 1010 -------- 1010 

Note that the result is 1 only if both the top and bottom numbers in the same column are 1.

PHP way of writing:

 <?php echo 10 & 10; ?> Result: 10 

What is the practical use? Take an example: There are 4 sets of double doors. Both doors must open at the same time so that a person can go through. The number 1 is assigned to the open door. Number 2 is assigned to the closed door.

1010 means that the first door is open, the second is closed, the third is open, the fourth is closed. When all the doors are closed, they will look like this:

 0000 <-- first set of doors 0000 <-- second set of doors 

To allow someone to go through the leftmost door, the doors should be:

 0001 0001 

It is all fine, but there is a faster way to annotate it. The bitwise operator &. We do between both doors and get the result 1. Therefore, if the data is stored as 1, we know that the leftmost doors were open.

To open the leftmost door, the combination should be:

 1000 1000 

The result of the bitwise operator is decimal 8. Use a calculator similar to that on miniwebtool to do some math.

On the other hand, when the doors open and close all day, you can record when both doors of any of the 4 doors opened. This is just a long answer to a simple question.

+9
source

Posted this as a comment on the original question:

They are bitwise operators. Here it is what they do (this is a javascript implementation).

+4
source

They are the bitwise operators used in the laravel where() method, and they are supplied as fingerprints, you can find more information about these opreators here.

+2
source

Source: https://habr.com/ru/post/1236075/


All Articles