try {
$dbh = new PDO(‘sqlite:xiaokyun.sqlite’);
$dbh->exec("CREATE TABLE xiaokyun(id integer primary key AUTOINCREMENT,
xiaokyun varchar(233) NOT NULL UNIQUE,
info varchar(233) default ‘xiaokyun’)");
$dbh->exec("INSERT INTO xiaokyun(xiaokyun, info) values(‘http://www.xiaokyun.com/’, ‘xiaokyun’)");
$dbh->beginTransaction();
$sth = $dbh->prepare(‘SELECT * FROM xiaokyun’);
$sth->execute();
$result = $sth->fetchAll();
print_r($result);
$dbh=null;
}
catch (PDOException $e){
echo ‘Connection failed: ‘ . $e->getMessage();
$dbh=null;
}
Tag: conn.php
MySQL conn.php
define(‘DB_NAME’, ”);
define(‘DB_USER’, ”);
define(‘DB_PASSWORD’, ”);
define(‘DB_HOST’, ”);$link = mysql_connect(DB_HOST,DB_USER,DB_PASSWORD) or die (‘数据库连接失败!</br>错误原因:’.mysql_error());
mysql_query("set names ‘utf8’");
mysql_select_db(DB_NAME,$link) or die(‘数据库选定失败!</br>错误原因:’.mysql_error());
$result = mysql_query($sql) or die(‘数据库查询失败!</br>错误原因:’.mysql_error());