3
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ロリポップでSQLiteを使う

Posted at

#ロリポップでSQLiteを使う
一番安いプランが月額100円なので遊び用にロリポップのレンタルサーバーを契約しましたが、最安プランでもSQLiteが使えるので、せっかくだから使い方を調べてみました。
特になにか設定などは必要なく、PHPだとソース中に new PDO('sqlite:~') と書くだけで使用できるようです。

##サンプル

<?php
header('Content-type: text/plain; charset=utf-8');

$conn = new PDO('sqlite:./test.db');

$conn->exec("create table if not exists aaa(xxx, yyy) ");

$sth = $conn->prepare('insert into aaa(xxx, yyy)values(:xxx, :yyy)');
for ($i = 0; $i < 100; $i++) {
    $sth->bindValue(':xxx', $i, PDO::PARAM_INT);
    $sth->bindValue(':yyy', $i + 100, PDO::PARAM_INT);
    $sth->execute();
}

echo date(DATE_ATOM), "\n";
foreach ($conn->query("select xxx, yyy from aaa") as $row) {
    echo "{$row['xxx']}\t{$row['yyy']}\n";
}
$conn->exec("delete from aaa");
3
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?