草庐IT

tri-grams

全部标签

php - 代码点火器 3 : Can't catch database error using try catch block

我正在开发一个api,它处理来自客户端的请求,然后从服务器获取响应(使用codeigniter3开发)并将其转发回客户端。但是,如果出现任何数据库错误,例如重复ID或空值,模型类将无法处理该错误以显示正确的错误消息。我试过trycatchblock但还没有成功。这是模型:publicfunctionadd(){try{$this->db->trans_start(FALSE);$this->db->insert('users',$preparedData);$this->db->trans_complete();if($this->db->trans_status()===FALSE)

php - 上传未保存的文件时为 "Trying to get property of non-object"

我有一个模型具有使用OctoberCMS的system_files的文件关系。public$attachOne=['return_file'=>['System\Models\File','public'=>false,'delete'=>true]];在fields.yaml中我有表格return_file:label:AttachFiletype:fileuploadmode:filespan:right现在,在保存之前或之后,我想将图像从其目录移动到我的插件中的自定义目录。afterSave()似乎没有检索文件路径来移动它。但是在system_files中我看到在MySQLwor

php - 为什么 Yii2 因 try/catch 而崩溃?

我插入一个条目,其中有一个主键的副本。publicfunctionactionInc(){$add=newCountry();$add->code='QI';$add->name='Qiang';$add->population='4444444';try{$add->save();return$this->render('inc',['count'=>'Ok',]);}catch(Exception$exception){return$this->render('inc',['count'=>'Error',]);}}但是我需要那个应用程序不宕机,继续工作,但是就是不行...

php - Symfony 2 服务器部署 fatal error : It tries to open localhost file

我制作了一个symfony2应用程序,并尝试将其部署到共享服务器上,但出现fatalerror。我在这里采取了推荐的步骤:Deployment-Tools我已经更新了供应商依赖项:phpcomposer.pharinstall--optimize-autoloader我已经清除了缓存:phpapp/consolecache:clear--env=prod--no-debug我已经更改了服务器上app/cache和app/logs的权限但它不起作用。这是错误:Fatalerror:Uncaughtexception'UnexpectedValueException'withmessage

PHP fatal error : Allowed memory size of 1073741824 bytes exhausted (tried to allocate 16777216 bytes)

我在我的16GBMacBookPro上运行了composerinstall,我得到了这个⚡️distributor-portalcomposerinstallLoadingcomposerrepositorieswithpackageinformationUpdatingdependencies(includingrequire-dev)PHPFatalerror:Allowedmemorysizeof1073741824bytesexhausted(triedtoallocate16777216bytes)inphar:///usr/local/bin/composer/src/Co

php - LARAVEL -> 为什么 try catch 在 Laravel 中不起作用?

我在RouteServiceProvider中有代码:$router->bind('user',function($value){try{throw(new\Symfony\Component\HttpKernel\Exception\NotFoundHttpException);}catch(Exception$e){exit('nott');}});我没有得到输出nott我得到了Sorry,thepageyouarelookingforcouldnotbefound.NotFoundHttpExceptioninRouteServiceProvider.phpline75:...编

php - JWT 解码 try catch

我在我的小项目中使用JWT进行授权(RESTAPI)。JWT看起来非常适合我的项目。假设我有这段代码:$key="secret";$token="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.TJVA95OrM7E2cBab30RMHrHDcEfxjoYZgeFONFh7HgQ"$data=JWT::decode($token,$key,array('HS256'));此代码将返回一个数组,如JWT的官方页面所示。​​但是

php - 我可以在将 html 文件加载到 DOMDocument 时 try catch PHP 警告吗?

是否有可能进行某种trycatch来捕获警告?例如if(!$dom->loadHTMLFile($url)){//ifcantloadfilehandleerrormyway}对于我正在使用的$urlWarning(2):DOMDocument::loadHTMLFile(MYURL)[domdocument.loadhtmlfile]:failedtoopenstream:HTTPrequestfailed!HTTP/1.0403Forbidden[APP\controllers\import_controller.php,line62]Warning(2):DOMDocument:

PHP - try/catch 的开销是否高于 if/then?

在处理一些遗留代码时,我遇到了大量的Try/Catch语句。Try/Catch不是他们在我的Zend认证类(class)中教授的东西,而且10年来我没有与使用它的其他PHP开发人员一起工作。与执行if语句相比,Try/Catch是否有额外的开销?是什么让它比其他选择更受欢迎或更不受欢迎? 最佳答案 我不认为它们彼此真正相关。If语句用于确定分支逻辑。Try/Catch是处理发生的错误。可以在Catchblock中处理会使程序停止的异常。 关于PHP-try/catch的开销是否高于if/

php - try catch laravel 不适用于重复输入

我在LaravelController中使用以下代码。并得到username的重复错误,但我需要通过try-catch来处理它。此代码无效。insert(['username'=>$request->username,'phone'=>$request->phone,'status'=>1]);}catch(Exception$exception){$errormsg='Databaseerror!'.$exception->getCode();}returnResponse::json(['success'=>$result,'errormsg'=>$errormsg]);}}我遇到