1
sqlite 데이터베이스를 mysql로 변환했습니다.PHP를 사용하여 sqlite를 mysql로 변환하는 방법
그렇다면 MySQL + PHP 코드로 sqlite + 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;
DB 연결, $ con = mysql_connect ("localhost", "root", "") 또는 die ("error1"); $ db = mysql_select_db ("decsys", $ con) 또는 die ("error2") –
아니요, 이미 PDO를 사용하고 있습니다. 그것을 계속 사용하십시오! mysql_connect와 친구는 더 이상 사용되지 않으며 곧 삭제 될 것입니다. 업데이트 된 답변보기 – egig
고마워 Mr.Charlie. 너는 내 하루를 구했다 !! –