为什么我的 PHP 不返回 MySQL 存储过程?

Why won't my PHP return a MySQL stored procedure?

提问人:Andrew G. Johnson 提问时间:1/25/2009 最后编辑:Andrew G. Johnson 更新时间:1/25/2009 访问量:368

问:

好吧,我有我编写的这个MySQL存储过程,如果我在phpMyAdmin中运行以下内容,事情会正确返回:

SELECT game_name,urlfriendly(game_name) AS game_name2 FROM games

但是,如果我尝试运行以下代码,则会出现错误“警告:在 # 行的 /filepath.php 中为 foreach() 提供的参数无效”

foreach ($this->database->query("SELECT game_name,urlfriendly(game_name) AS game_name2 FROM games") as $games)
{
    echo $games["game_name"] . " " . $games["game_name2"];
}

但是,如果我运行它,一切正常:

foreach ($this->database->query("SELECT game_name FROM games") as $games)
{
    echo $games["game_name"];
}

这意味着存储的过程不会返回到 PHP。

有什么想法吗?

编辑这是存储的过程(但我怀疑这是问题所在,因为phpMyAdmin正在从中提取值)

定界符//

DROP FUNCTION urlfriendly
//
CREATE FUNCTION urlfriendly (unsafe TEXT) RETURNS TEXT

DETERMINISTIC

BEGIN

DECLARE safe TEXT;

SET safe = REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(LOWER(unsafe),' ','-'),'&','and'),'`',''),'~',''),'!',''),'@',''),'#',''),'$',''),'%',''),'^',''),'*',''),'(',''),')',''),'_',''),'+',''),'=',''),'[',''),'{',''),']',''),'}',''),'|',''),'\\',''),"'",""),'"',''),':',''),';',''),'<',''),',',''),'>',''),'.',''),'/',''),'?','');

RETURN safe;

END
//

编辑2这是从MySQL返回的错误

execute command denied to user 'username'@'localhost' for routine 'databasename.urlfriendly' )
PHP 的MySQL

评论


答:

3赞 Paolo Bergantino 1/25/2009 #1

你能得到errorInfo吗?

你能运行吗:

GRANT EXECUTE ON `database`.* TO 'username'@'localhost'

从phpMyAdmin?

评论

0赞 Greg 1/25/2009
对于 PDO,您需要 print_r($this->database->errorInfo())。我猜如果它在phpmyadmin中起作用,那就是权限问题。
0赞 Andrew G. Johnson 1/25/2009
这似乎是一个权限问题,知道如何解决吗?(我会在问题正文中发布实际返回的错误)
0赞 Andrew G. Johnson 1/25/2009
我的访问被拒绝了,我想我可能需要与我的服务器提供商联系
0赞 Paolo Bergantino 1/25/2009
听起来差不多。我对MySQL中的权限和用户等不太熟悉,但我认为你找到了罪魁祸首。:)