Code issue with php5 class and stored procedure

Discussion in 'PHP' started by iamyoohoo, May 25, 2007.

  1. #1
    I use the following code:

    $db1 = new Sql();
    $sSQL = "CALL insert_user ('".$_REQUEST['username']."','".$_REQUEST['password']."','".$_REQUEST['email']."','".$_REQUEST['bcountry']."','".$_REQUEST['ncountry']."',0);";
    $rc = $db1->data($sSQL);
    // set session values for userid, email and username
    $_SESSION['userid'] = $rc->insertid;
    $_SESSION['username'] = trim($_REQUEST['username']);
    $_SESSION['email'] = trim($_REQUEST['email']);

    sql is a new class that uses mysqli like the code below:
    class Sql extends mysqli {
    function __construct() {
    // eventually user-password information should be read from a file outside public_html directory
    parent::__construct("localhost", "username", "password", "dbname");
    }

    function data($SQL, $force=0) {
    static $holdQuery;
    static $result;

    if ($SQL != $holdQuery) {
    $result = $this->query($SQL) or print $this->error;
    $holdQuery = $SQL;
    }

    return $result;
    }

    PROBLEM: The stored procedure when run from mysql returns the value of insertid - but does not return or store it into the session variable userid above on the next page. The other session variables(username and email) do return a value on next page so i dont know whats wrong - please help.

    Thanks.
     
    iamyoohoo, May 25, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    Post your whole code. And please use [php] [/php] tags.
     
    nico_swd, May 25, 2007 IP
  3. iamyoohoo

    iamyoohoo Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Sorry for not using the tags. But this is my whole code.

    The class is called within a php page. That php page is included in the calling page and the class is initialized as db1. There is a statement in the stored procedure
    select LAST_INSERT_ID() as insertid;

    which returns a value when i execute it from mysql - but does not return a value here ....

    Here is the code again - with the php tags

    
    
    $db1 = new Sql();
    $sSQL = "CALL insert_user ('".$_REQUEST['username']."','".$_REQUEST['password']."','".$_REQUEST['email']."','".$_REQUEST['bcountry']."','".$_REQUEST['ncountry']."',0);";
    $rc = $db1->data($sSQL);
    // set session values for userid, email and username
    $_SESSION['userid'] = $rc->insertid;
    $_SESSION['username'] = trim($_REQUEST['username']);
    $_SESSION['email'] = trim($_REQUEST['email']);
    
    sql is a new class that uses mysqli like the code below:
    class Sql extends mysqli {
    function __construct() {
    // eventually user-password information should be read from a file outside public_html directory
    parent::__construct("localhost", "username", "password", "dbname");
    }
    
    function data($SQL, $force=0) {
    static $holdQuery;
    static $result;
    
    if ($SQL != $holdQuery) {
    $result = $this->query($SQL) or print $this->error;
    $holdQuery = $SQL;
    }
    
    return $result;
    }
    
    
    PHP:
     
    iamyoohoo, May 25, 2007 IP