[php-src] Issue #8356: PHP 8.1 PDO (Probably a Bug) : SQLSTATE[42S22]: Column not found: 1054 Unknown column 'school_types.type_id' in 'where clause'
in
| From: | ReturnMe | Date: | Wed, 13 Apr 2022 03:00:06 +0000 |
| Subject: | [php-src] Issue #8356: PHP 8.1 PDO (Probably a Bug) : SQLSTATE[42S22]: Column not found: 1054 Unknown column 'school_types.type_id' in 'where clause' in |
||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-240913@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/8356
Author: ReturnMe
### Description
I've checked the column and table names are all correct.
**All of these codes work with PHP 7.4, as I mentioned in the note below.**
**When I upgraded to PHP 8.1, it generates the error I mentioned.**
Table names, parameters etc. are all correct.
Strangely enough, I get such an error with PHP 8.1. Is there anyone who can help? I've gone
through at least 30 different threads about this here, but none of them solved my problem.
SQL:
SELECT schools.school_name,
schools.id,
schools.city_id,
cities.city_name AS city_name,
districts.district_name AS district_name,
Group_concat(school_types.type_id) AS school_types,
0 AS school_total_students,
0 AS school_total_teachers,
"-" AS school_total_plans
FROM schools
LEFT JOIN cities
ON cities.id = schools.city_id
LEFT JOIN districts
ON districts.id = schools.district_id
LEFT JOIN school_types
ON school_types.school_id = schools.id
WHERE ( schools.school_name LIKE :school_name )
AND ( schools.city_id = :city_id )
AND ( schools.district_id = :district_id )
AND ( schools.official = :school_official )
AND ( school_types.type_id = :school_types )
GROUP BY school_types.school_id
ORDER BY schools.id DESC
LIMIT 0, 10
PHP PDO:
// The query above:
$stmt = $this->db::$db->prepare($query);
// PDO parameters are also completely in the array.
/*
where_values output =>
Array
(
[school_name] => %a%
[city_id] => 2
[district_id] => 128
[school_official] => 1
[school_types] => 2
)
*/
foreach($search['where_values'] as $key => &$value) {
$stmt->bindParam(':' . $key, $value);
}
$stmt->execute();
$data = $stmt->fetchAll(PDO::FETCH_ASSOC);
Error:
Uncaught PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column
'school_types.type_id' in 'where clause' in......
**NOTE: PDO query that works with PHP 7.4 does not work in PHP 8.1.**
### PHP Version
8.1
### Operating System
Redhat