実際に遭遇した例

PHP用語集

カテゴリー: Fatal error  閲覧数:1378 配信日:2014-10-22 08:47


エラーメッセージ


Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'public' in where clause is ambiguous' in /〇〇.php:42


エラー発生箇所


    public function fetchAllElem()
   {
       $sql = "
           SELECT a.*, u.display_name, u.site_id, s.situation, s.color, z.*,e.elem_title,e.elem_url
               FROM entry a
                   LEFT JOIN user u ON a.user_id = u.id
                 LEFT JOIN state s ON a.state_id = s.state_id
                 
                  LEFT JOIN(
                     SELECT
                       a.category_id, a.category, a.parent_id,
                         CASE WHEN a.parent_id = 0
                         then a.fonticon
                         else b.fonticon
                         end AS fonticon,

                         CASE WHEN a.parent_id = 0
                         then a.color
                         else b.color
                         end  AS color,

                         CASE WHEN a.parent_id = 0
                         then a.category
                         else b.category
                         end AS parent_category,
                       
                         CASE WHEN a.parent_id = 0
                         then a.category_id
                         else a.parent_id
                         end AS parent_id2      
                     FROM
                       category a
                     LEFT JOIN
                       category b on a.parent_id = b.category_id        
                    AS z ON a.category_id = z.category_id                

                   RIGHT JOIN elem e ON a.id = e.entry_id

               WHERE public = 1
               ORDER BY GREATEST(a.`created_at`,a.`modified`) DESC
       ";

       return $this->fetchAll($sql);
   }



エラー原因


・publicカラムがどのテーブルに所属しているか不明


エラー修正


所属テーブル名付与
・a.public
    public function fetchAllElem()
   {
       $sql = "
           SELECT a.*, u.display_name, u.site_id, s.situation, s.color, z.*,e.elem_title,e.elem_url
               FROM entry a
                   LEFT JOIN user u ON a.user_id = u.id
                 LEFT JOIN state s ON a.state_id = s.state_id
                 
                  LEFT JOIN(
                     SELECT
                       a.category_id, a.category, a.parent_id,
                         CASE WHEN a.parent_id = 0
                         then a.fonticon
                         else b.fonticon
                         end AS fonticon,

                         CASE WHEN a.parent_id = 0
                         then a.color
                         else b.color
                         end  AS color,

                         CASE WHEN a.parent_id = 0
                         then a.category
                         else b.category
                         end AS parent_category,
                       
                         CASE WHEN a.parent_id = 0
                         then a.category_id
                         else a.parent_id
                         end AS parent_id2      
                     FROM
                       category a
                     LEFT JOIN
                       category b on a.parent_id = b.category_id        
                    AS z ON a.category_id = z.category_id                

                   RIGHT JOIN elem e ON a.id = e.entry_id

               WHERE a.public = 1
               ORDER BY GREATEST(a.`created_at`,a.`modified`) DESC
       ";

       return $this->fetchAll($sql);
   }


週間人気ページランキング / 4-22 → 4-28
順位 ページタイトル抜粋 アクセス数
1 Parse error: syntax error, unexpected 'public' (T_PUBLIC) | Parse error(エラーメッセージ) 15
2 ブラウザを閉じたらセッションデータはどうなるの? | セッション 10
3 PHPで定数を定義する方法は2種類ある / 配列定数の定義 5
3 curl で Cookie を使用する 5
3 Composer | 依存関係マネージャ 5
4 コード例 … 「例外処理」はネストすることができる 4
4 Warning: strlen() expects parameter 1 to be string, array given in ○○.php on line △△ | Warning(エラーメッセージ) 4
4 ブラウザを閉じたらセッションデータはどうなるの? | セッション 4
5 Fatal error: Uncaught Error: Call to a member function modify() on string | Fatal error(エラーメッセージ) 3
5 Fatal error: Access level to ▲::$△ must be protected (as in class ●) or weaker | Fatal error(エラーメッセージ) 3
6 関数 2
6 PHP フレームワーク | フレームワーク 2
6 セッション管理が必要な理由は、HTTPプロトコルには状態を保持する機能がないため | セッション 2
6 ( ! ) Fatal error: Uncaught PDOException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'カラム名' cannot be null | Fatal error(エラーメッセージ) 2
6 ( ! ) Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined | Fatal error(エラーメッセージ) 2
6 T_CONSTANT_ENCAPSED_STRING | エラーメッセージ 2
6 セッション名 | セッション 2
6 型の種類 | 型 2
6 例外処理 | 制御構造 2
6 register_shutdown_function | 関数処理 関数 2
2024/4/29 1:01 更新
指定期間人気ページランキング / 2020-5-28 → 2024-4-28
順位 ページタイトル抜粋 アクセス数
1 PHP用語 6620
2 ブラウザを閉じたらセッションデータはどうなるの? | セッション 2181
3 Parse error: syntax error, unexpected 'public' (T_PUBLIC) | Parse error(エラーメッセージ) 2100
4 ブラウザを閉じたらセッションデータはどうなるの? | セッション 1544
5 【テスト投稿】テスト | 1130
6 セッション管理が必要な理由は、HTTPプロトコルには状態を保持する機能がないため | セッション 911
7 Fatal error: Access level to ▲::$△ must be protected (as in class ●) or weaker | Fatal error(エラーメッセージ) 730
8 PHPで定数を定義する方法は2種類ある / 配列定数の定義 719
9 Fatal error: Uncaught Error: Call to a member function modify() on string | Fatal error(エラーメッセージ) 717
10 Fatal error: require_once(): Failed opening required 'PEAR.php' | Fatal error(エラーメッセージ) 705
11 インターフェイス | クラスとオブジェクト 687
12 コード例 … 「例外処理」はネストすることができる 674
13 定数 670
14 Fatal error: Uncaught RuntimeException: SplFileObject::__construct(): failed to open stream: Permission denied in | Fatal error(エラーメッセージ) 648
15 curl で Cookie を使用する 640
16 メンバー | クラスとオブジェクト 637
17 Fatal error: Uncaught HeadlessChromium\Exception\OperationTimedOut: Operation timed out (3sec) in | Fatal error(エラーメッセージ) 605
18 Warning: include() [function.include]: Failed opening '**.php' for inclusion (in | Warning(エラーメッセージ) 592
19 ( ! ) Fatal error: Uncaught PDOException: SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column | Fatal error(エラーメッセージ) 562
20 セッション名 | セッション 536
2024/4/29 1:01 更新