我在用
$rows = $statement->fetchAll(PDO::FETCH_ASSOC);
Run Code Online (Sandbox Code Playgroud)
得到我桌子的所有行.
模式定义为"id INTEGER PRIMARY KEY,title TEXT,year INTEGER,price REAL"
来自fetchAll结果的一行是
array(4) {
[0]=>
string(1) "1"
[1]=>
string(14) "The Dark Night"
[2]=>
string(4) "2008"
[3]=>
string(5) "19.95"
}
Run Code Online (Sandbox Code Playgroud)
为什么所有数据类型都以字符串形式返回?我希望它们按照架构中的定义返回.我理解SQLite的"无类型"特性,但它们确实将有限的数据类型定义为TEXT,INTEGER和REAL.如何使用指定的数据类型返回数据?我不想遍历每一行,并用PHP转换它 - 这似乎太慢了.
完整的测试代码如下:
<?
class sqlite_test {
function __construct()
{
$this->dbase_filename = "test.sqlite";
$this->init_dbase();
}
function init_dbase()
{
$this->pdo = new PDO("sqlite:".$this->dbase_filename);
}
function open_table()
{
$table = "dvds";
if ( ! ($test_to_see_if_table_exists = $this->pdo->query("SELECT 1 from $table")) ) {
$schema = "id INTEGER PRIMARY KEY, title TEXT, year …Run Code Online (Sandbox Code Playgroud)