Php 如何获得DB insert laravel的反馈
我的数据库插入查询如下Php 如何获得DB insert laravel的反馈,php,laravel,laravel-5,Php,Laravel,Laravel 5,我的数据库插入查询如下 DB::table('job_details')->insert([ 'job_id' => $jobId, 'item_id' => $itemId, 'type_id' => $typeId, 'qty' => $qnty, 'laminating' => $laminating, 'mat_id' =>
DB::table('job_details')->insert([
'job_id' => $jobId,
'item_id' => $itemId,
'type_id' => $typeId,
'qty' => $qnty,
'laminating' => $laminating,
'mat_id' => $matId,
'rates' => $rates,
'sqft' => $sqft,
'ups' => $ups,
'master_qty' => $masterQnty
]);
我想知道查询是成功还是失败 插入
方法
返回一个布尔值
您可以将结果保存在变量中并检查结果是否为真
$queryState = DB::table('job_details')->insert([...])
if($queryState) {
// the query succeed
} else {
// the query failed
}
插入
方法
返回一个布尔值
您可以将结果保存在变量中并检查结果是否为真
$queryState = DB::table('job_details')->insert([...])
if($queryState) {
// the query succeed
} else {
// the query failed
}
在laravel中执行DB操作时,该方法将返回true或false响应。对于捕获异常,您可以将代码保留在try catch块中
try{
$response= DB::table('job_details')->insert([
'job_id' => $jobId,
'item_id' => $itemId,
'type_id' => $typeId,
'qty' => $qnty,
'laminating' => $laminating,
'mat_id' => $matId,
'rates' => $rates,
'sqft' => $sqft,
'ups' => $ups,
'master_qty' => $masterQnty
]);
if($response)
echo 'Query was successfull';
else
echo 'There was some error';
}catch{
print_r($e->getMessage);
}
在laravel中执行DB操作时,该方法将返回true或false响应。对于捕获异常,您可以将代码保留在try catch块中
try{
$response= DB::table('job_details')->insert([
'job_id' => $jobId,
'item_id' => $itemId,
'type_id' => $typeId,
'qty' => $qnty,
'laminating' => $laminating,
'mat_id' => $matId,
'rates' => $rates,
'sqft' => $sqft,
'ups' => $ups,
'master_qty' => $masterQnty
]);
if($response)
echo 'Query was successfull';
else
echo 'There was some error';
}catch{
print_r($e->getMessage);
}
$results=DB::….
$results=DB::….
但如果抛出异常,则整个过程将中断。。对吗?如果查询执行失败,输出是什么?您可以在这里看到返回类型,但如果抛出异常,则整个过程将中断。。对吗?如果查询执行失败,输出是什么?您可以在这里看到返回类型