2
我有一個MySQL的動態SQL語句,我想使用PDO來運行它,我也得到了以下錯誤消息:SQLSTATE [HY000]:常規錯誤
警告:PDOStatement對象::使用fetchall() pdostatement.fetchall]: SQLSTATE [HY000]:在C常規錯誤:\ XAMPP \ htdocs中\標籤\上 線29
cobasql.php這裏是我的PHP代碼:
<?php
$uname = 'root'; //nama username database
$pwd = ''; //Password database
$dbname = 'eav_latihan'; //nama Database
/* Initialisasi database */
$db = new PDO('mysql:host=localhost;dbname='.$dbname, $uname, $pwd);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
$query = "SET @sql = NULL; ".
" SELECT GROUP_CONCAT(DISTINCT CONCAT('MAX(IF(a.Name = ''', ".
" a.Name, ''', ca.value, NULL)) AS ', a.Name)) INTO @sql ".
" FROM cust_attribute ca ".
" INNER JOIN attribute a ON ca.idAttribute = a.idAttribute ".
" INNER JOIN customer c ON c.idCustomer = ca.idCustomer ".
" WHERE a.publish = 'Y'; ".
" SET @sql = CONCAT('SELECT c.idCustomer, c.namaCustomer, ' ".
" ' c.email, c.noTelp, ', @sql, ' FROM cust_attribute ca', ".
" ' INNER JOIN attribute a ON ca.idAttribute = a.idAttribute', ".
" ' INNER JOIN customer c ON c.idCustomer = ca.idCustomer', ".
" ' GROUP BY c.idCustomer'); ".
" SELECT @sql; ".
" prepare stmt FROM @sql; ".
" execute stmt;";
$result_array = array();
$queryku = $db->query($query);
$result_array = $queryku->fetchAll(PDO::FETCH_OBJ);
echo $result_array;
?>
這裏的任何人都可以幫我或給我一個建議嗎?
請告訴我,那不是你如何渲染你' $ query' ...雖然很高興看到你使用PDO。 – nickhar
你是什麼意思? –
您不需要在查詢中使用'「SELECT」,「this」,「that」,當您可以使用''SELECT this,that''來實現時,不需要使用'「SELECT」來連接查詢元素。 – nickhar