这里php读取mysql结果集为什么不能用存储过程

aquastar aquastar 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
首先创建一个mysql存储过程

CREATE DEFINER=`root`@`localhost` PROCEDURE `News_getAll`()
select * from news;


接着我在php操作类里面写了一个方法
mysql.class.php:

function News_getAll() {
$allnews = array ();
$i = 0;
$result = mysql_query("select * from news");
while ($row = mysql_fetch_row($result)) {
$allnews[$i] = $row;
$i++;
}
return $allnews;
}


然后再用smarty模板输出
index.php:

<?php
include "smarty_inc.php";
include "mysql.class.php";

$db = new mysql('localhost', 'root', '', 'tianmei', 'GBK');
$allnews=$db->News_getAll();


$smarty->assign('allnews', $allnews);
$smarty->display('index.html');
?>


我的模板页是
index.html:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> New Document </title>
</head>

<body>

{foreach item=v from=$allnews }
{$v[0]}
{$v[1]}
{$v[2]}
{$v[3]}<br>
{/foreach}


</body>
</html>


结果是可以正常显示,但是如果我把操作类的
$result = mysql_query("select * from news");

换成
$result = mysql_query("call News_getAll()");

就报错 为 mysql_fetch_row(): supplied argument is not a valid MySQL result resource

如果有人知道可请教我这里如何调用存储过程
...全文
评论 5
收藏 已收藏
分享
返回顶部
aquastar
基础编程 21,889 成员 140,329 内容