用PHP操作sqlite数据库

时间:2012-08-02 点击:统计中..
a、 如何连接sqlite数据库?
  if ($db = sqlite_open('mysqlitedb', 0666, $sqliteerror)) {
  select * from sqlite_master;
  echo "数据库连接成功!n
  ";
  } else {
  die($sqliteerror);
  }
  b、 如何列出数据库中所有的表?
  if ($db = sqlite_open('mysqlitedb', 0666, $sqliteerror)) {
  $result = sqlite_array_query($db, 'select * from sqlite_master;');
  foreach ($result as $entry) {
  echo 'talbe name='.$entry['name']."
  n";
  echo 'sql='.$entry['sql']."
  n";
  echo "
  --------------------------------------------------------------------------------
  ";
  }
  sqlite_close($db);
  } else {
  die($sqliteerror);
  }}
  c、 对sqlite数据库的查询,以及结果集的显示
  if ($db = sqlite_open('mysqlitedb', 0666, $sqliteerror)) {
  $result = sqlite_array_query($db, 'select name, email from user ', SQLITE_ASSOC);
  echo "user表查询结果:
  n";
  echo " n name email
  n";
  foreach ($result as $entry) {
  echo ' '.$entry['name']." " $entry['email']."
  n";
  }
  echo ' ';
  sqlite_close($db);
  } else {
  die($sqliteerror);
  }
  d、 数据库对象记录的增加、删除、修改
  sqlite_query($db, "INSERT INTO user VALUES('user".$i."'" ",'user".$i."@ hichina. com')");
  sqlite_query($db, "delete from user where user=’user99’");
  sqlite_query($db, 'UPDATE user SET email="lilz@ hichina .com" where name="user1"');

赞助商链接

热门内容

相关内容



联系我们

联系方式