知識社群Login
PHP with Sqlite
by 艾鍗學院, 2012-04-30 16:20, Views(2008)


SQLite PHP tutorial


=======================

This is an extension for the SQLite Embeddable SQL Database Engine. SQLite is a C library that implements an embeddable SQL database engine. Programs that link with the SQLite library can have SQL database access without running a separate RDBMS process.

SQLite is not a client library used to connect to a big database server. SQLite is the server. The SQLite library reads and writes directly to and from the database files on disk.

The SQLite extension is enabled by default as of PHP 5.0. Beginning with PHP 5.4, the SQLite extension is available only via PECL.



What is PECL?

PECL is a repository for PHP Extensions, providing a directory of all known extensions and hosting facilities for downloading and development of PHP extensions.

The packaging and distribution system used by PECL is shared with its sister, PEAR

PEAR - PHP Extension and Application Repository

PHP Data Objects

The PHP Data Objects (PDO) extension defines a lightweight, consistent interface for accessing databases in PHP. Each database driver that implements the PDO interface can expose database-specific features as regular extension functions. Note that you cannot perform any database functions using the PDO extension by itself; you must use a database-specific PDO driver to access a database server.

PDO provides a data-access abstraction layer, which means that, regardless of which database you're using, you use the same functions to issue queries and fetch data. PDO does not provide a database abstraction; it doesn't rewrite SQL or emulate missing features. You should use a full-blown abstraction layer if you need that facility.

PDO ships with PHP 5.1, and is available as a PECL extension for PHP 5.0; PDO requires the new OO features in the core of PHP 5, and so will not run with earlier versions of PHP.



------

 Installation 

- repeat the compile process below for pdo, sqlite and pdo-sqlite extensions,
  (gcc is required and may have to be installed)

    tar xvf php-your.version.here.tar.gz
    cd php-your.version.here/ext/sqlite/
    phpize
    ./configure
    make
    make install

    
- create file /etc/php.d/sqlite.ini:

    ; Enable sqlite extension module
    extension=pdo.so
    extension=sqlite.so
    extension=pdo_sqlite.so

- [restart apache] service httpd restart

- search phpinfo(); for 'sqlite' to verify correct installation\

phpize ?? 

phpize 是屬於 php-devel 中的東西,主要是設定 php 外掛模組的一些設定
所以安裝 php-devel 相關套件就會有 phpize 可以使用 (檔案預設存放於 /usr/bin/phpize ) 


phpize 命令是用來準備 PHP 外掛模組的編譯環境的。下面例子中,外掛模組的源程序位於 extname 目錄中:


$ cd extname
phpize
$ ./configure (註一)
$ make
$ make install

成功的安裝將建立 extname.so 並放置於 PHP 的外掛模組目錄中 (預設存放於 /usr/lib/php/modules/ 內) 。
需要調整 php.ini,加入 extension=extname.so 這一行之後才能使用此外掛模組。



./configure –with-php-config=/usr/bin/php-config


if you have multiple PHP versions installed, you may be able to specify for which installation you'd like to build by using the --with-php-config option during configuration.

--with-php-config=[Insert path to proper php-config here]

For example (my case):
./configure --with-php-config=/usr/local/php5/bin/php-config5