I have a mysql dynamic-sql statement and I want to run it using pdo, and I get the following error message:
Warning: PDOStatement::fetchAll() [pdostatement.fetchall]: SQLSTATE[HY000]: General error in C:\\xampp\\htdocs\\tags\\cobasql.php on line 29
Here's my php code:
<?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;
?>
Anyone here can help me or give me a suggest please??
It seams like you cant connect!
This line here
$db = new PDO('mysql:host=localhost;dbname='.$dbname, $uname, $pwd);
Try to remove the $dbname var and type in a right value so your line looks like
$db = new PDO('mysql:host=localhost;dbname=dbname', $uname, $pwd);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.