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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
xiaofei
Forum Newbie
Posts: 4
Joined: Tue Jul 24, 2007 11:22 am

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

Post 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]
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post 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?
Post Reply