私はphpMyAdminのでこれをチェックしました、そして、それは1件の結果返さ:私は、phpMyAdminの中でこれを確認し、そしてそれはCOUNT = 1返さPHP/MySQLのPDOのための奇妙な行数のリターン
SELECT id, name
FROM tbl_product_category
INNER JOIN tbl_product_cat_basket AS basket
ON id = basket.cat_id
WHERE basket.product_id = 2
LIMIT 0,1
を:
をfunction getProductCategory($product_id) {
$sql = "SELECT id, name FROM tbl_product_category
INNER JOIN tbl_product_cat_basket AS basket
ON id = basket.cat_id
WHERE basket.product_id = ?
LIMIT 0,1;";
$data = array((int)$product_id);
$rows = dbRowsCount($sql, $data);
logErrors("getProductCategory(".$product_id.") returned rows: ".$rows);
if ($rows == 1) {
dbQuery($sql, $data);
return dbFetch();
} else {
return null;
}
}
:これは空の文字列またはnullを返すように$rows
の原因となる理由
SELECT COUNT(*)
FROM tbl_product_category
INNER JOIN tbl_product_cat_basket AS basket
ON id = basket.cat_id
WHERE basket.product_id = 2
LIMIT 0,1
は今、私は理解していません
getProductCategory(1)返された行:
getProductCategory(2)返された行:
getProductCategory(3)返された行:
getProductCategory(4)返された行:
getProductCategory方法は私に、この出力を与えます(5)返される行:
ですので、null
をメソッドから返します。
私のdbRowsCount(...)
メソッドは、SELECT COUNT(*)
を実行するようにSQLを変換し、次にdbQuery(...)
が実際のクエリを実行します。今のところdbRowsCount(...)
が他のクエリの正しい行を返すので、これは奇妙です。
ここでは、とにかくです:
function dbRowsCount($sql, $data) {
global $db, $query;
$regex = '/^SELECT\s+(?:ALL\s+|DISTINCT\s+)?(?:.*?)\s+FROM\s+(.*)$/i';
if (preg_match($regex, $sql, $output) > 0) {
$query = $db->prepare("SELECT COUNT(*) FROM {$output[1]}");
$query->setFetchMode(PDO::FETCH_NUM);
if ($data != null)
$query->execute($data);
else
$query->execute();
if (!$query) {
echo "Oops! There was an error: PDOStatement returned false.";
exit;
}
return $query->fetchColumn();
}
return false;
}
だから、間違って何? [元のクエリ] [正規表現の後にクエリ]
SELECT id, name FROM tbl_product_category INNER JOIN tbl_product_cat_basket AS basket ON id = basket.cat_id WHERE basket.product_id = ? LIMIT 0,1;
SELECT COUNT(*) FROM tbl_product_category
getProductCategory(1) returned rows: 7
SELECT id, name FROM tbl_product_category INNER JOIN tbl_product_cat_basket AS basket ON id = basket.cat_id WHERE basket.product_id = ? LIMIT 0,1;
SELECT COUNT(*) FROM tbl_product_category
getProductCategory(2) returned rows: 7
SELECT id, name FROM tbl_product_category INNER JOIN tbl_product_cat_basket AS basket ON id = basket.cat_id WHERE basket.product_id = ? LIMIT 0,1;
SELECT COUNT(*) FROM tbl_product_category
getProductCategory(3) returned rows: 7
SELECT id, name FROM tbl_product_category INNER JOIN tbl_product_cat_basket AS basket ON id = basket.cat_id WHERE basket.product_id = ? LIMIT 0,1;
SELECT COUNT(*) FROM tbl_product_category
getProductCategory(4) returned rows: 7
SELECT id, name FROM tbl_product_category INNER JOIN tbl_product_cat_basket AS basket ON id = basket.cat_id WHERE basket.product_id = ? LIMIT 0,1;
SELECT COUNT(*) FROM tbl_product_category
getProductCategory(5) returned rows: 7
SELECT id, name FROM tbl_product_category INNER JOIN tbl_product_cat_basket AS basket ON id = basket.cat_id WHERE basket.product_id = ? LIMIT 0,1;
SELECT COUNT(*) FROM tbl_product_category
getProductCategory(6) returned rows: 7
SELECT id, name FROM tbl_product_category INNER JOIN tbl_product_cat_basket AS basket ON id = basket.cat_id WHERE basket.product_id = ? LIMIT 0,1;
SELECT COUNT(*) FROM tbl_product_category
getProductCategory(7) returned rows: 7
SELECT id, name FROM tbl_product_category INNER JOIN tbl_product_cat_basket AS basket ON id = basket.cat_id WHERE basket.product_id = ? LIMIT 0,1;
SELECT COUNT(*) FROM tbl_product_category
getProductCategory(8) returned rows: 7
SELECT id, name FROM tbl_product_category INNER JOIN tbl_product_cat_basket AS basket ON id = basket.cat_id WHERE basket.product_id = ? LIMIT 0,1;
SELECT COUNT(*) FROM tbl_product_category
getProductCategory(9) returned rows: 7
SELECT * FROM tbl_store_admin WHERE php_sesskey=?;
SELECT COUNT(*) FROM tbl_store_admin WHERE php_sesskey=?;
SELECT * FROM tbl_menu_cat_basket WHERE menu_id=?;
SELECT COUNT(*) FROM tbl_menu_cat_basket WHERE menu_id=?;
SELECT * FROM tbl_menu_cat_basket WHERE menu_id=?;
SELECT COUNT(*) FROM tbl_menu_cat_basket WHERE menu_id=?;
SELECT * FROM tbl_menu_cat_basket WHERE menu_id=?;
SELECT COUNT(*) FROM tbl_menu_cat_basket WHERE menu_id=?;
SELECT * FROM tbl_menu_cat_basket WHERE menu_id=?;
SELECT COUNT(*) FROM tbl_menu_cat_basket WHERE menu_id=?;
SELECT * FROM tbl_menu_cat_basket WHERE menu_id=?;
SELECT COUNT(*) FROM tbl_menu_cat_basket WHERE menu_id=?;
SELECT * FROM tbl_menu_cat_basket WHERE menu_id=?;
SELECT COUNT(*) FROM tbl_menu_cat_basket WHERE menu_id=?;
SELECT * FROM tbl_menu_cat_basket WHERE menu_id=?;
SELECT COUNT(*) FROM tbl_menu_cat_basket WHERE menu_id=?;
SELECT * FROM tbl_product ORDER BY last_update ASC;
SELECT COUNT(*) FROM tbl_product ORDER BY last_update ASC;
'$ output [1]'はどのように見えますか? – jeroen
'var_dump(" SELECT COUNT(*)FROM {$ output [1]} ");' – zerkms
@jeroen @zerkms何らかの理由で$ rows = 7を返すようになりました!正規表現の出力は次のようになります: 'SELECT COUNT(*)FROM tbl_product_category'が間違っています – Ozzy