gpt4 book ai didi

php - 声明在 phpmyadmin 上工作但不通过 php

转载 作者:行者123 更新时间:2023-11-29 02:30:59 26 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
PDO support for multiple queries (PDO_MYSQL, PDO_MYSQLND)

我在这里有一个声明..当我从 phpmyadmin 运行它时..我的查询有效..但是当我从 php 执行它时却没有..

这是我的查询(语句)

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;

这是我在 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);
var_dump($result_array);
?>

这里有人可以帮助我或给我建议吗??

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com