FaaPz / PDO

Just another PDO database library
MIT License
316 stars 103 forks source link

stop excuting when field value is not expected #69

Closed sh7ning closed 7 years ago

sh7ning commented 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();
}