tags:

views:

221

answers:

1

Well I have this MySQL stored procedure that I wrote and if I run the following in phpMyAdmin things return properly:

SELECT game_name,urlfriendly(game_name) AS game_name2 FROM games

However if I try to run the following code I get the error "Warning: Invalid argument supplied for foreach() in /filepath.php on line #"

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

However if I run this it all goes fine:

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

Meaning the stored proc won't return to PHP.

Any ideas?

EDIT Here's the stored proc (but I doubt it is the issue as phpMyAdmin is pulling values back from it just fine)

DELIMITER //

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
//

EDIT2 Here is the error returned from MySQL

execute command denied to user 'username'@'localhost' for routine 'databasename.urlfriendly' )
+3  A: 

Can you get the errorInfo?

Can you run:

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

From phpMyAdmin?

Paolo Bergantino
Didn't show anything -- will that work with PDO?
Andrew G. Johnson
No, for PDO try http://us2.php.net/manual/en/pdostatement.errorinfo.php
Paolo Bergantino
For PDO you need print_r($this->database->errorInfo()). I'm guessing it's a permissions thing if it works in phpmyadmin.
Greg
It seems like a permissions issue, any idea how to fix? (I'll post the actual returned error in the question body)
Andrew G. Johnson
I'm getting access denied, I think I may need to talk to my server provider
Andrew G. Johnson
Sounds about right, then. I'm not overly familiar with permissions and users and such in MySQL but I think you found your culprit. :)
Paolo Bergantino