[PHP x SQLite3]PHPでSQLite3 #4データ挿入(INSERT)
PHPでSQLite3 #4データ挿入(INSERT)
$sql="INSERT INTO $tableName(name,title,cnt) VALUES('{$name}','{$title}',1)"; $result=$db->query($sql);
PHPでSQLite3 #4データ挿入(INSERT)
$sql="INSERT INTO $tableName(name,title,cnt) VALUES('{$name}','{$title}',1)"; $result=$db->query($sql);
PHPでSQLite3 #3データ取得(SELECT)
$tableName="access"; $sql="SELECT id,name,cnt FROM $tableName WHERE name='{$name}' ORDER BY cnt ASC"; $result=$db->query($sql); $tmp=[]; while ($row = $result->fetchArray(SQLITE3_ASSOC)) { $tmp[]=$row; } echo json_encode($tmp); $db->close();
データ重複しないように取得
$sql="SELECT DISTINCT name FROM $tableName"; $result=$db->query($sql); if($result===FALSE){ $db->close(); echo $message; exit; } $tmp=[]; while ($row = $result->fetchArray(SQLITE3_ASSOC)) { $value=$row['name']; $tmp[]=$value; } echo json_encode($tmp);
PHPでSQLite3 #2テーブル作成
$tableName="access"; $sql="create table if not exists $tableName (id INTEGER PRIMARY KEY AUTOINCREMENT, name varchar(6), title text, cnt int)"; $result=$db->query($sql); if ($result===FALSE) { $db->close(); echo $message; exit; } $db->close();
PHPでSQLite3 #1接続
try { $db = new SQLite3('test.db'); } catch (Exception $e) { echo $message; exit; }