6

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;
gin93r
  • 1,551
  • 4
  • 21
  • 39

2 Answers2

13

Found out a way to get this working here:

$result = DB::select('call getLibraryList(?)',array($email));
Community
  • 1
  • 1
gin93r
  • 1,551
  • 4
  • 21
  • 39
  • This isn't completely valid since you do not retrieve a specific class, you get an stdClass object. – Tom Hofman Feb 13 '15 at 13:34
  • 1
    What if i i have 3 other out parameters also then what should i do –  May 31 '15 at 12:26
  • Alternative is : $result = DB::select(DB::raw("CALL retrieve_bill_home(:user_id)"), array( 'user_id' => $user_id )); – Hashmat Waziri Apr 16 '16 at 08:00
  • @gin93r Maybe you can help me. Look at this : https://stackoverflow.com/questions/51838922/how-can-i-convert-many-statement-mysql-to-laravel-eloquent – moses toh Aug 15 '18 at 07:57
3

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());
Antonio Carlos Ribeiro
  • 86,191
  • 22
  • 213
  • 204
  • Results in the same. I actually tried that before - though I didn't have the semicolon before. Still - same results. – gin93r Mar 19 '14 at 21:02
  • Thanks for the Help @Antonio I found an answer. :) – gin93r Mar 19 '14 at 21:10
  • @Antonio Carlos Ribeiro Maybe you can help me. Look at this : https://stackoverflow.com/questions/51838922/how-can-i-convert-many-statement-mysql-to-laravel-eloquent – moses toh Aug 15 '18 at 07:57