PHP PDO / Retrieving OUT Parameters from MySQL Stored Procedure -
i need retrieve out parameters mysql stored procedure. can't find explains (and makes sense me).
try { $dsn = 'mysql:dbname=db_name;host=localhost'; $dbh = new pdo($dsn, 'usr_name', 'password'); } catch (pdoexception $e) { echo 'connection failed: ' . $e->getmessage(); } $stmt = $dbh->prepare("call db.stprnewuser(:usremail,:newuserok,:stprcomment)"); $stmt->bindparam(':usremail', $tmpemail, pdo::param_str); $stmt->bindparam(':newuserok', $newuserok, pdo::param_int,1); $stmt->bindparam(':stprcomment', $stprcomment, pdo::param_str,100); $stmt->execute(); $outputarray = $dbh->query("select @newuserok, @stprcomment")->fetch(pdo::fetch_assoc); print "procedure returned [" . $outputarray['@newuserok'] . $outputarray['@stprcomment'] . "]\n";
i found last 2 lines on item, returns null values.
try this... see if works...
try { $dsn = 'mysql:dbname=db_name;host=localhost'; $dbh = new pdo($dsn, 'usr_name', 'password'); } catch (pdoexception $e) { echo 'connection failed: ' . $e->getmessage(); } //$stmt = $dbh->prepare("call db.stprnewuser(:usremail,:newuserok,:stprcomment)"); //changed :newuserok @newuserok //changed :stprcomment @stprcomment $stmt = $dbh->prepare("call db.stprnewuser(:usremail,@newuserok,@stprcomment);"); //declare input parameters. //good pratice put string length. assuming varchar(100). $stmt->bindparam(':usremail', $tmpemail, pdo::param_str,100); //dont need these // $stmt->bindparam(':newuserok', $newuserok, pdo::param_int,1); // $stmt->bindparam(':stprcomment', $stprcomment, pdo::param_str,100); $stmt->execute(); $outputarray = $dbh->query("select @newuserok, @stprcomment;")->fetchall(); foreach($outputarray $row) { "newuserok:" . $row["@newuserok"] . ", stprcomment:" . $row["@stprcomment"]; } //$outputarray = $dbh->query("select @newuserok, @stprcomment")->fetch(pdo::fetch_assoc); //print "procedure returned [" . $outputarray['@newuserok'] . $outputarray['@stprcomment'] . "]\n";
Comments
Post a Comment