En una configuración de servidor experimento un error muy extraño. Hay PHP 5.3.6 con PDO Driver para MySQL, biblioteca de cliente versión 5.1.61. Todo está compilado a mano.PDO bindValue con PDO :: PARAM_BOOL hace que la sentencia se ejecute falle silenciosamente
Cuando vinculo parámetros con bindValue y establezco el tercer parámetro como \ PDO :: PARAM_BOOL, la sentencia ejecuta return return false y no ocurre nada (no se insertan datos en MySQL, incluso ninguna excepción). Cuando no uso el tercer parámetro, va bien. De hecho no puedo ommit tercer parámetro, bacues Doctrine2 DBAL establece que mientras que los parámetros de conversión ...
Aquí está el código:
<?php
$pdo = new \PDO('mysql:host=***;dbname=***', '***', '***'); // hidden DB access
$pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
$stmt = $pdo->prepare('insert into outage (name, description, start_at, end_at, is_exception, extranet_id) values (?,?,?,?,?,?)');
$stmt->bindValue(1, 'Test name', \PDO::PARAM_STR);
$stmt->bindValue(2, 'Test desc', \PDO::PARAM_STR);
$stmt->bindValue(3, '2012-01-01 00:00:00', \PDO::PARAM_STR);
$stmt->bindValue(4, null, \PDO::PARAM_NULL);
$stmt->bindValue(5, false, \PDO::PARAM_BOOL);
$stmt->bindValue(6, 2, \PDO::PARAM_INT);
var_dump(array('stmt result' => ($result = $stmt->execute()), 'last insert id' => $pdo->lastInsertId(), 'stmt err code' => $stmt->errorCode(), 'pdo err code' => $pdo->errorCode()));
Resultado:
array(4) {
["stmt result"]=>
bool(false)
["last insert id"]=>
string(1) "0"
["stmt err code"]=>
string(5) "00000"
["pdo err code"]=>
string(5) "00000"
}
¿Qué podría salir mal? Lo probé en otros 4 servidores y no obtuve este error. Además, si paso '0' (como una cadena) a $stmt->bindValue(5, false, \PDO::PARAM_BOOL);
, funciona bien.
OK, el problema se resuelve en PHP 5.3.10 en este servidor (Red Hat 5.4) –