代碼1:
<html>
<?php
$dsn = 'sqlite:sql.db';
try
{
$dbh = new PDO($dsn, $user, $password); //建立連接
echo 'PDO Connection Ok<BR>';
//建表
$dbh->exec("CREATE TABLE PKU(id integer,name varchar(255))");
//echo 'Create Table ok<BR>\n ';
print("Create Table ok<BR>\n");
$dbh->exec("INSERT INTO PKU values(1,'jarjin')");
echo 'Insert Data ok<BR>';
$dbh->beginTransaction();
$sth = $dbh->prepare('SELECT * FROM PKU');
$sth->execute();
//獲取結果
$result = $sth->fetchAll();
print_r($result);
$dsn=null;
}
catch (PDOException $e)
{
echo 'Connection failed: ' . $e->getMessage();
$dsn = null;
}
?>
</html>