遭遇例2

MySQL用語集

カテゴリー: エラー  閲覧数:301 配信日:2017-10-29 11:29


エラー対応


修正前
public function fetchByParentCategoryid2new($category_id)
{
$sql = "
 SELECT
   a.id AS id,
   a.category_id AS category_id,
   a.state_id AS state_id,
   a.counter AS counter,
   a.created_at AS created_at,
   a.modified AS modified,
   a.body AS body,
   topic_name,
   r.modified AS rmodified,
   r.body AS rbody,
   u.display_name, u.site_id, c.category, c.parent_id,s.situation, s.fonticon,s.color,relationentrynum
 FROM
   status AS a
 LEFT JOIN user u ON a.user_id = u.id
 LEFT JOIN category c ON a.category_id = c.category_id
 LEFT JOIN state s ON a.state_id = s.state_id
LEFT OUTER JOIN(
   SELECT
     topic_id,`body`, MAX(modified) AS modified, COUNT(topic_id) AS `relationentrynum`
  FROM
     res
   GROUP BY topic_id
 ) AS r ON a.id = r.topic_id";
$where = array();
$bind = array();
foreach ($category_id as $val) {
 $where[] = 'a.`category_id` = ? ';//単一キーワード
 $bind[] = '' . $val . '';
}
$sql .= ' where ' . implode('or ', $where);
$sql .= ' and public = 1 ';
$sql .= 'ORDER BY a.created_at ASC';
return $this->fetchAll($sql, $bind);
}


修正後
ANY_VALUE(`body`)
public function fetchByParentCategoryid2new($category_id)
{
$sql = "
 SELECT
   a.id AS id,
   a.category_id AS category_id,
   a.state_id AS state_id,
   a.counter AS counter,
   a.created_at AS created_at,
   a.modified AS modified,
   a.body AS body,
   topic_name,
   r.modified AS rmodified,
   r.body AS rbody,
   u.display_name, u.site_id, c.category, c.parent_id,s.situation, s.fonticon,s.color,relationentrynum
 FROM
   status AS a
 LEFT JOIN user u ON a.user_id = u.id
 LEFT JOIN category c ON a.category_id = c.category_id
 LEFT JOIN state s ON a.state_id = s.state_id
LEFT OUTER JOIN(
   SELECT
     topic_id,ANY_VALUE(`body`) AS body, MAX(modified) AS modified, COUNT(topic_id) AS `relationentrynum`
  FROM
     res
   GROUP BY topic_id
 ) AS r ON a.id = r.topic_id";
$where = array();
$bind = array();
foreach ($category_id as $val) {
 $where[] = 'a.`category_id` = ? ';//単一キーワード
 $bind[] = '' . $val . '';
}
$sql .= ' where ' . implode('or ', $where);
$sql .= ' and public = 1 ';
$sql .= 'ORDER BY a.created_at ASC';
return $this->fetchAll($sql, $bind);
}



セッション系のSQLでエラーが発生。仕組みだけ作成して、クッキー設定していなかったから?

指定期間人気ページランキング / 2020-5-28 → 2025-4-24
順位 ページタイトル抜粋 アクセス数
1 #1241 - オペランドに 1 個の列が必要です。 | エラー 3601
2 MySQL用語 1560
3 SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry | エラー 1356
4 クエリエラー: #1265 - 列 'カラム名' の 行 ★ でデータが切り捨てられました。 | エラー 1335
5 ( ! ) Fatal error: Uncaught PDOException: SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value | エラー 927
6 Data truncated for column | エラー 608
7 where clause is ambiguous | エラー 600
8 Incorrect integer value | エラー 582
9 クエリエラー: #1294 - 列 'カラム名' に ON UPDATE旬は無効です。 | エラー 567
10 <> | 演算子 477
11 スキーマ | データベースの構造 451
12 インデックス | 最適化 407
13 #1067 - Invalid default value for 'id' | エラー 389
14 SELECT list is not in GROUP BY clause and contains nonaggregated column | エラー 265
15 #3106 - 'Fulltext index on virtual generated column' is not supported for generated columns. | エラー 245
16 問題発生 / ハマった点 / indexを確認 243
17 エラーメッセージ / エラー原因 / エラー対応 239
18 遭遇例1.INT型カラムに空文字INSERT 238
19 #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ★★ at line △△ | エラー 233
20 phpMyAdmin上で、VARCHARデータ型カラム を FLOATデータ型カラム へ変更しようとしたら、エラー発生 228
2025/4/25 1:01 更新