Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从'transactions'中选择*,其中的'order_id'类似于''%115%''_Php_Mysql_Database_Laravel - Fatal编程技术网

Php 从'transactions'中选择*,其中的'order_id'类似于''%115%''

Php 从'transactions'中选择*,其中的'order_id'类似于''%115%'',php,mysql,database,laravel,Php,Mysql,Database,Laravel,不使用like运算符从序列化数据返回行 Select * from `transactions` where 'order_id' like "'%115%'" 在代码中,您试图匹配的不是列名称,而是字符串“order_id”与字符串“%115%”之间的匹配,而字符串“%115%”显然不匹配,因此您没有行结果。然后 避免在列名周围使用单引号,并使用concat作为适当的like条件 Select * from `transactions` where order_id like concat(

不使用like运算符从序列化数据返回行

Select * from `transactions` where 'order_id' like "'%115%'"

在代码中,您试图匹配的不是列名称,而是字符串“order_id”与字符串“%115%”之间的匹配,而字符串“%115%”显然不匹配,因此您没有行结果。然后

避免在列名周围使用单引号,并使用concat作为适当的like条件

Select * from `transactions` where order_id like concat('%', '115', '%')
并确保订单id为字符串数据类型列,否则应使用

Select * from `transactions` where order_id =115

使用以下选项之一:

1如果您的order_id字段是整数,并且您希望获得准确的值,请尝试此操作

SELECT * FROM `transactions` WHERE order_id = 115
SELECT * FROM `transactions` WHERE CAST(order_id AS CHAR) LIKE '%115%'
2如果您的订单id字段是整数,并且您希望获得匹配的值,请尝试此操作

SELECT * FROM `transactions` WHERE order_id = 115
SELECT * FROM `transactions` WHERE CAST(order_id AS CHAR) LIKE '%115%'
3如果订单id字段为字符串并存储为序列化数据,请尝试以下操作

SELECT * FROM table WHERE field REGEXP '.*"array_key";s:[0-9]+:".array_value.".*'

ex. : SELECT * FROM `transactions` WHERE order_id REGEXP '.*"m5";s:[0-9]+:"115".*'
4如果订单id字段存储为简单字符串,请尝试以下操作

SELECT * FROM `transactions` WHERE order_id LIKE '%115%'

我希望这将对您有所帮助:

显示您的示例数据和预期输出。在您的表中,order\u id是字符串还是整数?请检查此线程: