mysqli执行存储过程后返回的结果集字段有缺失
我写了一个统计发布数的proc,结果在navi里显示结果正常,所有的ip都能做为字段列出来,但是在mysqli调用时,他只显示了一个ip,实在是找不到原因了!求各位大神指点!
表A结构
create table(
years int,
months date,
weeks int,
days date,
pubcount int,
ip varchar(50)
);
生成的表B结构
create table(
param varchar(50),#这个是根据参数来显示的【1:years,2:months,3:weeks,5:days】
ip1,
ip2,
ip...,#[这里根据A表实际的IP字段数据生成]
ipn,
total
)
下面是具体的SQL PROC代码,表A的结构也是根据phpcms的v9_news表生成的按日统计结果,也就是temp_public_data临时表
CREATE DEFINER=`root`@`localhost` PROCEDURE `jc_adv_count_public`(IN `pType` INT,IN `pDayBegin` date,IN `pDayEnd` date)
BEGIN
DECLARE sTYPE VARCHAR(20);
DROP TEMPORARY TABLE IF EXISTS temp_public_data;
CREATE TEMPORARY TABLE temp_public_data SELECT
DATE_FORMAT(FROM_UNIXTIME(n.inputtime),'%Y-%m-%d') as days,
DATE_FORMAT(FROM_UNIXTIME(n.inputtime),'%Y-%m') as months,
DATE_FORMAT(FROM_UNIXTIME(n.inputtime),'%Y') as years,
DATE_FORMAT(FROM_UNIXTIME(n.inputtime),'%u') as weeks,
count(n.id) as pubnum,n.username from v9_news as n
WHERE DATE_FORMAT(FROM_UNIXTIME(n.inputtime),'%Y-%m-%d') BETWEEN pDayBegin AND pDayEnd
GROUP BY days,n.username;
IF pType=1 THEN
SET sType = "years";
ELSEIF pType=2 THEN
SET sType = "months";
ELSEIF pType=3 THEN
SET sType = "weeks";
ELSEIF pType=5 THEN
SET sType = "days";
END IF;
SET @SQLLEN = "";
SET @EE = "";
SELECT @EE:= CONCAT(@EE,',SUM(IF(username=\'',username,'\',pubnum,0)) AS \'',username,'\'') AS SQLSTR FROM (SELECT DISTINCT username FROM temp_public_data) A ORDER BY LENGTH(SQLSTR) DESC LIMIT 0,1;
SET @SQL = CONCAT('SELECT IFNULL(',sType,',\'TOTAL\') AS MONTH');
SET @SQL = CONCAT(@SQL,@EE);
SET @SQL = CONCAT(@SQL,',SUM(pubnum) as TOTAl ');
SET @SQL = CONCAT(@SQL,' FROM temp_public_data');
SET @SQL = CONCAT(@SQL,' GROUP BY ',sType,' WITH ROLLUP;');
#SELECT @SQL;
PREPARE stmt FROM @SQL;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
DROP TEMPORARY TABLE IF EXISTS temp_public_data;
END
结果在navi下生成的结果集是正确的,所有的IP都能正常显示,如图
而在php中使用mysqli调用却只显示了一个IP
用fetch_fiels显示也只有三个字段
PHP代码如下
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论