简体   繁体   English

SQL OR不返回所有行

[英]SQL OR not returning all rows

I'm having what may be the dumbest issue. 我遇到的可能是最愚蠢的问题。
I'm using phpmyadmin and when I query a table using OR it does not return all values. 我正在使用phpmyadmin,当我使用OR查询表时,它不会返回所有值。
This is the query that is not returning all values: 这是不返回所有值的查询:
SELECT * FROM ecrdatabase.ecrtable m WHERE m.ecrChangeOwner = '$partialOwner' OR m.ecrInitByName = '$partialOwner' . SELECT * FROM ecrdatabase.ecrtable m WHERE m.ecrChangeOwner = '$partialOwner' OR m.ecrInitByName = '$partialOwner'
Here, $partialOwner is passed from $_GET['user'] . 在这里, $partialOwner是从$_GET['user']传递的。
Some of the rows are returned - just not all of them. 返回某些行-并非全部。 I have a php page that queries the database and I have tried running the query directly on the database through phpmyadmin using query: 我有一个查询数据库的php页面,我尝试使用query通过phpmyadmin直接在数据库上运行查询:
SELECT * FROM ecrtable WHERE ecrChangeOwner = 'ecunningham' OR ecrInitByName = 'ecunningham' . SELECT * FROM ecrtable WHERE ecrChangeOwner = 'ecunningham' OR ecrInitByName = 'ecunningham'

Both results from the the direct query and php page return the same number of rows. 直接查询和php页面的两个结果都返回相同数量的行。
I have also tried: 我也尝试过:
SELECT * FROM ecrtable WHERE (ecrChangeOwner = 'ecunningham' OR ecrInitByName = 'ecunningham') . SELECT * FROM ecrtable WHERE (ecrChangeOwner = 'ecunningham' OR ecrInitByName = 'ecunningham')

What am I missing? 我想念什么? I have more complex queries that run fine. 我有更复杂的查询,可以很好地运行。 Please tell me I'm just missing something stupid... 请告诉我,我只是想念一些愚蠢的东西...

You really should be using prepared statements here, first of all. 首先,您确实应该在这里使用准备好的语句。 You are wide open to injection attacks. 您很容易受到注入式攻击。

Second, how do you know that this query does not return all the rows? 其次,您如何知道该查询不会返回所有行? What queries have you done to verify that this one is wrong? 您进行了哪些查询来验证这一错误?

If you run a union what do you get: 如果您经营工会,您将获得:

SELECT * FROM ecrtable WHERE ecrChangeOwner = 'ecunningham'
UNION ALL
SELECT * FROM ecrtable WHERE ecrInitByName = 'ecunningham')

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

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