我已将 sqlite 数据库转换为 mysql。
那么我需要将 sqlite+php 代码转换为 mysql+php 代码。您是否有任何包含将 sqlite 转换为 mysql 的方法的文档。
谢谢..
这是我的代码
<?php
try {
//open the database
$db = new PDO('sqlite:cars.sqlite'); //will create the file in current directory. Current directory must be writable
//create the database if does not exist
$db->exec("CREATE TABLE IF NOT EXISTS cars (id INTEGER PRIMARY KEY, manufacturer TEXT, year INTEGER, price INTEGER)");
//select all data from the table
$select = $db->prepare('SELECT * FROM cars ORDER BY id ASC LIMIT 100');
$select->execute();
$out = array(
'cars' => $select->fetchAll(PDO::FETCH_ASSOC)
);
echo json_encode($out);
// close the database connection
$db = NULL;
}
catch (PDOException $e) {
print 'Exception : ' . $e->getMessage();
}
?>
mysql表:汽车
CREATE TABLE IF NOT EXISTS `cars` (
`id` int(11) NOT NULL DEFAULT '0',
`manufacturer` text,
`year` int(11) DEFAULT '0',
`price` text,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;