Closed sh7ning closed 7 years ago
fix error with value is array which field need string,so that framework can handle error before excute.
exapmle:
._testInsert.php
<?php //handle errors error_reporting(-1); ini_set('display_errors', 'Off'); set_error_handler('handleError'); function handleError($errorno, $errorstr, $errorfile, $errorline) { if (error_reporting() & $errorno) { throw new ErrorException($errorstr, 0, $errorno, $errorfile, $errorline); } } require_once 'vendor/autoload.php'; $pdo = new \Slim\PDO\Database('pgsql:host=127.0.0.1;port=5432;dbname=dbname', 'develop', ''); ######### table: users ######### //field //------ id int //------ name varchar(12) ######### end ######### $insertStatement = $pdo->insert(array('id', 'name')) ->into('users') ->values(array(123, array('your_name'))); try { $insertId = $insertStatement->execute(false); var_dump('succ:', $insertId); } catch (\Exception $e) { echo 'error:', $e->getMessage(); }
before fix:
run cmd:php ._testInsert.php result:error:Array to string conversion but the database insert successfully select * from users ; id name 123 Array
run cmd:php ._testInsert.php
php ._testInsert.php
result:error:Array to string conversion but the database insert successfully
error:Array to string conversion
select * from users ;
after fix:
run cmd:php ._testInsert.php result:error:Array to string conversion and the database doesn't insert data.
result:error:Array to string conversion and the database doesn't insert data.
fix error with value is array which field need string,so that framework can handle error before excute.
exapmle:
._testInsert.php
before fix:
after fix: