Page 1 of 1

can not convert object to string??????PLEASE HELP

Posted: Thu Oct 25, 2007 1:19 pm
by xiaofei
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


i have this stored function that would essentially return variable, the code is as follow:
[syntax="sql"]CREATE DEFINER=`DATABASE`@`%` FUNCTION `sf_GetUserID`(inUserEmail varchar(200)) RETURNS char(7) CHARSET latin1
BEGIN
       declare returnUserID char(7);
       select userID into returnUserID
       from Users
       where userEmail = inUserEmail;
       return returnUserID;

END
-------------
i would then write the following in PHP:[/syntax]

Code: Select all

$getUserIDQuery = "call sf_GetUserID('".$inUserEmail."')";

    // executes the query string, and SHOULD assign the result to $userID.
    
    if($userID = $mysqli->query($getUserIDQuery))
    {
      echo (string)$userID;
      // testing to see if $row = $result->fetch_field() is really working. if it is, then print "<BR/>its working<BR/>"
     // if($row = $userID->fetch)
     // {
     //   print "<BR/>its working<BR/>";
     // }
     // echo $row[returnUserID];
    }
    else
    {
    echo "ERROR:".$mysqli->error."<BR/>"; 
    }
    $mysqli->close();
-------------
at first, it says that the stored funciton does not exist, but it DOES.
also, it also tells me that it can not convert it to string.
please help.
xiaofei


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Thu Oct 25, 2007 3:23 pm
by CoderGoblin
Don'T you need to cast the userid in the select (from what I guess is an integer) to a string ?

Have you tried the stored function without the php and checked if you get it working as you expect?