note 123919 added to pdostatement.errorinfo

From: Date: Sun, 09 Jun 2019 14:51:50 +0000
Subject: note 123919 added to pdostatement.errorinfo
Groups: php.notes 
Request: Send a blank email to php-notes+get-211200@lists.php.net to get a copy of this message
Seriously errorInfo is your friend. Use it. If these look like your google searches then you need errorInfo "no database error showing in php" "pdo selects from database but wont insert" "pdo insert not working" "isnt pdo just a big hype, should I go back to mysql?" "how much do surgeons make?" Trust me it will definitely save you hours of insanity if you make it a habit to use it in development. Forget E-ALL, it failed me since well, E-ALL apparently doesn't know that I didn't set a default value in my MySQL table and my query wasnt adding anything to it. So always do this <?php $sql = 'do something on a mysql table where foo = :bar'; $stmt = prepare($sql); $stmt->bindValue(':bar', $foo, PDO::PARAM_[DATA TYPE]); $stmt->execute(); // very important during development. But take it off in production $foo_arr = $stmt->errorInfo(); print_r($foo_arr); //Sample print_r return /* Array( [0] => HY000 [1] => 1364 [2] => Field 'phone' doesn't have a default value ) Never have I been so happy to see an error */ ?> While its common practice for any decent developer to always watch out and try to catch for errors, even the best of us make mistakes. This is not a replacement for exceptions, but the simplicity is priceless. ---- Server IP: 208.43.231.9 Probable Submitter: 82.199.130.26 (proxied: 197.210.29.26) ---- Manual Page -- http://php.net/manual/en/pdostatement.errorinfo.php Edit -- https://master.php.net/note/edit/123919 Del: integrated -- https://master.php.net/note/delete/123919/integrated Del: useless -- https://master.php.net/note/delete/123919/useless Del: bad code -- https://master.php.net/note/delete/123919/bad+code Del: spam -- https://master.php.net/note/delete/123919/spam Del: non-english -- https://master.php.net/note/delete/123919/non-english Del: in docs -- https://master.php.net/note/delete/123919/in+docs Del: other reasons-- https://master.php.net/note/delete/123919 Reject -- https://master.php.net/note/reject/123919 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#211200) next »