Using a stored procedure in Laravel 4

 ̄綄美尐妖づ 提交于 2019-12-30 04:58:11

问题


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;

回答1:


Found out a way to get this working here:

$result = DB::select('call getLibraryList(?)',array($email));



回答2:


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());


来源:https://stackoverflow.com/questions/22517903/using-a-stored-procedure-in-laravel-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!