PDOを利用してSQLiteへ接続
【開発環境】
xampp 1.8.3
PHP 5.5.9
SQLite バージョン 3.7.7.1
Eclipse 4.4
【SQLite】
1)コマンドプロンプトからデータベース「uriage」を作成
・フォルダーを変える
C:\Users\hiromi>cd C:\xampp\sqlite3
・データベース「uriage」を作る
C:\xampp\sqlite3>sqlite3 uriage.sqlite3
SQLite version 3.19.3 2017-06-08 14:26:16
Enter ".help" for usage hints.
sqlite>
・テーブルを作る
sqlite> create table shouhin(id,name);
sqlite>

2)データベース「uriage」の確認

3)SQLiteManagerを使ってデータを入れる
・名前:uriage を書き込んだら、参照ボタンをクリック

・「uriage.sqlite3」を選択し、保存ボタンを押す

・データベース「uriage」、テーブル「shouhin」が表示される

・テーブル「shouhin」をクリックし、「挿入」を選ぶ

・データを入力
データを入れ終えたら、保存後のチェックボタンを選び、保存ボタンを押す

・データ表示
上部の「表示」をクリックすると、全体のデータが表示される

4)SQLiteManagerだけでデータベース・テーブルを作ると、SQLiteManagerフォルダー内に作られるので注意が必要
【PDO使ってテーブルを表示させる】
1.プログラム「pdotest4.php」を書く
<html>
<head><title>PHP TEST</title></head>
<body>
<?php
$dsn ='sqlite:c:\xampp\sqlite3\uriage.sqlite3';
try {
// DBに接続する
$db = new PDO( $dsn, '', '' );
$db->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
print('接続に成功しました。<br>');
//データを取得し、全て配列化する
$qury='SELECT * FROM shouhin';
foreach ($db->query($qury) as $row) {
print($row['id']);
print($row['name'].'
');
}
}catch (PDOException $e){
print('Error:'.$e->getMessage());
die();
}
$dbh = null;
?>
</body>
</html>
2.表示

3.参照サイト
3流プログラマのメモ書き
PDOの利用(PHPBook)
※コメント投稿者のブログIDはブログ作成者のみに通知されます