Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using a stored procedure in Laravel 4

I'm trying to call a stored procedure from via a laravel route and i keep getting an error:

{"error":{"type":"Illuminate\\Database\\QueryException","message":"SQLSTATE[42S22]: Column not found: 1054 Unknown column 'emailAddress' in 'field list' (SQL: CALL getLibraryList(emailAddress))",

I believe the call I'm making is correct:

$result = DB::statement('CALL getLibraryList('.$email.')');
return $result;
like image 540
gin93r Avatar asked Mar 19 '14 20:03

gin93r


2 Answers

Found out a way to get this working here:

$result = DB::select('call getLibraryList(?)',array($email));
like image 148
gin93r Avatar answered Nov 02 '22 18:11

gin93r


You might find some trouble to execute them. Here are some options:

DB::statement(DB::raw('CALL getLibraryList('.$email.');'));

Or

DB::select('CALL getLibraryList(?)',array($email));

And, the dirtiest one:

$db = DB::connection();

$stmt = $db->pdo->prepare("CALL getLibraryList(?)");

$stmt->bindParam(1, $email);
$stmt->execute();

$search = array();

do {
    $search = $stmt->fetchAll(PDO::FETCH_CLASS, 'stdClass');
} while ($stmt->nextRowset());
like image 45
Antonio Carlos Ribeiro Avatar answered Nov 02 '22 17:11

Antonio Carlos Ribeiro