I have not managed to execute a stored procedure with parameter. Specifically I get this error:
"SQLSTATE [42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'getIngresosID (?) 'at line 1 (SQL: getIngresosID (2))
in the index I pass the parameter in this way:
<a href="{{URL::action('CuentaController@show',$cue->idcuenta)}}">
<button class="btn btn-primary">
Detalles
</button>
</a>
The procedure is in MariaDB and is as follows:
CREATE DEFINER='root'@'localhost' PROCEDURE 'getIngresosID'(in id int)
BEGIN
select i.idingreso, i.fecha, i.tipo_comprobante, i.num_comprobante, i.impuesto, i.estado, p.nombres, sum(di.cantidad*di.precio_compra) as total
from ingresos as i
join detalleingresos as di
on i.idingreso=di.ingreso_id
join personas as p
on i.provedor_id=p.idpersona
where i.idingreso=id
group by i.idingreso, p.nombres, i.tipo_comprobante, i.num_comprobante,
i.impuesto, i.estado;
END
The tables are the following:
In laravel I call the procedures this way:
namespace App\Http\Controllers;
use App\Persona;
use App\Ingreso;
use App\DetalleIngreso;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\Input;
use DB;
use Response;
use Illuminate\Support\Collection;
class IngresoController extends Controller
{
public function show($id)
{
$ingreso=DB::select('getIngresosID"'. $id.'"');
return view("compras.ingreso.show",["ingreso"=>$ingreso);
}
}
I have tried in several ways:
$ingreso=DB::select('getIngresosID(?)', array($id));
$ingreso=DB::select('getIngresosID ?', array($id));
$ingreso=DB::select('getIngresosID ?', $id);
With the first two I get the same error but in the last one I reported this error:
"Argument 1 passed to Illuminate \ Database \ Connection :: prepareBindings () must be of the type array, string given, called in C: \ xampp \ htdocs \ Pro_laravel \ crediPaisa