我知道的唯一“解决方法”是使用Coalesce()和Default(fieldname)
例如
$pdo = new PDO("mysql:host=localhost;dbname=test", 'localonly', 'localonly'); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);$pdo->exec(" CREATE TEMPORARY TABLE foo ( id int auto_increment, x int NOT NULL DEFAULT 99, y DATETIME NOT NULL DEFAULT '2010-03-17 01:00:00', z varchar(64) NOT NULL DEFAULT 'abc', primary key(id) )");$stmt = $pdo->prepare(' INSERT INTO foo (x,y,z) VALUES ( Coalesce(:x, Default(x)), Coalesce(:y, Default(y)), Coalesce(:z, Default(z)) )');$stmt->bindParam(':x', $x);$stmt->bindParam(':y', $y);$stmt->bindParam(':z', $z);$testdata = array( array(null, null, null), array(1, null, 'lalala'), array(null, '2009-12-24 18:00:00', null));foreach($testdata as $row) { list($x,$y,$z) = $row; $stmt->execute();}unset($stmt);foreach( $pdo->query('SELECt id,x,y,z FROM foo', PDO::FETCH_NUM) as $row) { echo join(', ', $row), "n";}版画
1, 99, 2010-03-17 01:00:00, abc2, 1, 2010-03-17 01:00:00, lalala3, 99, 2009-12-24 18:00:00, abc



