代码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>
时间: 2024-09-28 04:06:07