php  链接sqlite数据库   哪位高手知道?请教、、、急求

解决方案 »

  1.   

    $db = sqlite_open('库名');
    $rs = sqlite_query($db, 'select * from tbl_name');
    print_r(sqlite_fetch_all($rs));
      

  2.   


    这个跟mysql有什么区别吗?
      

  3.   

    没有太大区别,不过 sqlite 属于桌面数据库,不太适合存放大量数据和频繁访问
    如使用它的内存表并结合自定义函数,倒是可以简化很都复杂的算法
      

  4.   

    提一个代码给你看看class word {
      function word() {
        $this->db = sqlite_open(':memory:');
        sqlite_query($this->db, "CREATE TABLE strings(word, num,PRIMARY KEY (word))");
        sqlite_create_function($this->db, 'my', array($this, 'foo'), 2);
      }
      function add($str) {
        $n = strlen($str);
        $str = sqlite_escape_string($str);
        sqlite_query($this->db, "INSERT INTO strings VALUES ('$str', $n)");
      }  function foo($s, $v) {
        return $s == substr($this->dat, $this->i, $v);
      }
      function parse($s) {
        $this->i = 0;
        $this->dat = $s;
        $this->len = strlen($s);
        while($this->i < $this->len) $this->get();
      }
      function get() {
        $ch = $this->dat{$this->i};
        $rs = sqlite_query($this->db, "SELECT * from strings where  my(word, num) order by 1,2 desc");
        $num = sqlite_num_rows($rs);
        if( $num ) {
          $row = sqlite_fetch_array($rs, SQLITE_ASSOC );
          echo "<b>$row[word]</b>";
          $this->i += $row['num'];
        }else {
          echo $ch;
        }
        $this->i ++;
      }
      function test() {
        $rs = sqlite_query($this->db, "SELECT * from strings");
       echo $num = sqlite_num_rows($rs);
      }
    }$data = array(
       'one',
       'two',
       'three',
       'four',
       'five',
       'six',
       'seven',
       'eight',
       'nine',
       'ten',
       );$s = <<< TXT
    一.数词的定义
       数词是表示数目多少或先后顺序的词,有基数词和序数词两种。表数量的数词叫基数词,如one, two, three。表顺序的数词叫序数词,如first, second, third, fourth, fifth,...二.基数词
    (一)构成
    1)1~12单独记
     one, two, three, four, five, six, seven, eight, nine, ten, eleven, twelve
    2)13~19词尾为-teen:thirteen, fourteen, fifteen, sixteen, seventeen, eighteen, nineteen
    3)20~90逢整十词尾为-ty:twenty, thirty,forty,fifity,...
    4)21~ 99在十位数和个位数之间加连字符构成,如:
       73 seventy-three, 88 eighty-eight
    5)101~ 999先说几百,再加and,再加末尾两位数,如:
      178 one hundred and seventy-eight
    6)1000以上的数词,先从后向前数,每三位用一个数逗点“,”隔开。第一个“,”是thousand千,第二个“,”是million百万,第三个“,”是billion美语中的十亿(英国用thousand million),然后一节一节地用几百几十几的方法来数。
    TXT;$p = new word;
    foreach ($data as $str) {
      $p->add($str);
    }
    $p->parse($s);