CodeIgniter Forums
Mysql Stored Procedure: INOUT / OUT Paramter Support - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Mysql Stored Procedure: INOUT / OUT Paramter Support (/showthread.php?tid=32425)



Mysql Stored Procedure: INOUT / OUT Paramter Support - El Forum - 07-22-2010

[eluser]w3ttr3y[/eluser]
I'm really sorry if I missed this in the documentation or forums, but is it possible to use INOUT or OUT parameters with MySQL in the database library included with CodeIgniter?


Mysql Stored Procedure: INOUT / OUT Paramter Support - El Forum - 01-28-2011

[eluser]Unknown[/eluser]
I've resorted to using PDO for this. I was hoping CI had a more simple and elegant solution. Is there a better way to do this?

e.g.
Code:
try
        {
            $dbh = new PDO(DB_CONN, DB_USER, DB_PASS);

            $stmt = $dbh->prepare("CALL Accounts_Insert(
                                        @account_id,
                                        :email,
                                        :username)");

            $stmt->bindParam(':email', $email, PDO::PARAM_STR);
            $stmt->bindParam(':username', $username, PDO::PARAM_STR);

            $stmt->execute() or die (implode(':',$stmt->errorInfo()));

            //get output parameter
            foreach($dbh->query("SELECT @account_id as 'account_id'") as $row)
            {
                $account_id = $row['account_id'];
            }
        }
        catch(PDOException $e)
        {
            exit();
        }
        $dbh = NULL;