0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

中古ノート、買ってみた。 その14

Posted at

概要

中古ノート買ってみた。
wsl1、入れてみた。
ubuntu18.04 、入れてみた。
apache2,php,sqlite、入れてみた。
phpフレームワーク、cheetanを見つけたので、やってみた。
データベースをセットアップする。

サンプルコード

<?php
	try {
		$db = new PDO("sqlite:/var/www/db/test.db");
		echo "DB Connection OK" . "\n";
	}
	catch(PODException $e)
	{
		echo "DB Connection Failed" . $e->getMessage();
		exit;
	}
	$result = $db->exec("CREATE TABLE IF NOT EXISTS test(id INTEGER primary key AUTOINCREMENT, name VARCHAR(20), age INT(4), r_time DATETIME);");
	if ($result === false)
	{
		echo "DB Exec Failed  >>>  ";
		print_r($db->errorInfo());
		exit;
	}
	echo "Table Create OK" . "\n";
	var_dump($result);

	$result = $db->exec("INSERT INTO test(age, name) VALUES(1, 'apple'), (2, 'cherry'), (3, 'pizza');");
	if ($result === false)
	{
		print_r($db->errorInfo());
		exit;
	}
	echo "Table Insert OK" . "\n";
	var_dump($result);

	$result = $db->query("SELECT * FROM test;");
	while ($i = $result->fetch())
	{
		echo $i['id'] . "-" . $i['name'] . "\n";
	}

?>




実行結果

DB Connection OK
Table Create OK
int(0)
Table Insert OK
int(3)
1-apple
2-cherry
3-pizza
4-apple
5-cherry
6-pizza




以上。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?