note 118367 deleted from pdostatement.fetchcolumn by cmb

From: Date: Wed, 16 Dec 2015 16:32:12 +0000
Subject: note 118367 deleted from pdostatement.fetchcolumn by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-204433@lists.php.net to get a copy of this message
Note Submitter: ohcc at 163 dot com ---- When an invalid column offset is suplied, PDOStatement::fetch() with PDO::FETCH_COLUMN always returns the value of the first column of the first row. However, PDOStatement::fetchAll() with PDO::FETCH_COLUMN and an invalid column offset whill throw an exception instead. <?php $pdo = new PDO(....);// let's assume the database is connected. $PDOStatement = $pdo->query('SELECT * FROM WuXiancheng'); echo $PDOStatement->fetch(PDO::FETCH_COLUMN, -1); // minus column offset $PDOStatement = $pdo->query('SELECT * FROM WuXiancheng'); echo $PDOStatement->fetch(PDO::FETCH_COLUMN, 3691); // column offset is number greater than column count $PDOStatement = $pdo->query('SELECT * FROM WuXiancheng'); echo $PDOStatement->fetch(PDO::FETCH_COLUMN, 36.5); // column offset is a float number ?> Examples above will all input the first column value of the first row of data get from the database. This is really weird.

« previous php.notes (#204433) next »