当时是从安装phplib开始的
下载phplib
把phplib中的php目录复制到/var/www/
# cp -r php /var/www/
修改php.ini
auto_prepend_file = prepend.php3 #包含的文件
nclude_path = ".:/var/www/php" #指出查找的路径
在测试时会出现:
Fatal error: Call to undefined function pg_connect()
原因:php不支持pgsql。
解决方法,重新编译安装php。
重装php
-------------------------------------
./configure --with-pdo-pgsql --with-pgsql #重点啊
-------------------------------------
make
make install
指定使用的php
#find / -name php
/usr/bin/php
/usr/local/bin/php
#/usr/bin/php -v
5.3.3
#/usr/local/bin/php -v
5.3.6
我下的包是5.3.6,make install 后 ,php 安装在/usr/local/bin/中
通过测试知道 编译后的php能用
设置lighttpd.conf
fastcgi.server中的
"bin-path" => "/usr/bin/php-cgi"
更改为
"bin-path" => "/usr/local/bin/php-cgi"
更换原来的php及 php-cgi
#mv /usr/bin/php /usr/bin/php.bk
#mv /usr/bin/php-cgi /usr/bin/php-cgi.bk
#ln -s /usr/local/bin/php /usr/bin/php
ln -s /usr/local/bin/php-cgi /usr/bin/php-cgi
重启 lighttpd
/etc/init.d/lighttpd restart
测试
-----------------------------------------------------------------------------
数据准备
postgres@~$ /usr/local/pgsql/bin/createdb test
postgres@~$ /usr/local/pgsql/bin/psql test
postgres=# CREATE TABLE Countries (
postgres(# CountryID char(2) NOT NULL,
postgres(# CountryName varchar(255) NOT NULL,
postgres(# PRIMARY KEY (CountryID)
postgres(# );
CREATE TABLE
postgres=#
postgres=# INSERT INTO Countries VALUES ('AL', 'Albania');
postgres=# INSERT INTO Countries VALUES ('DZ', 'Algeria');
postgres=# INSERT INTO Countries VALUES ('AS', 'American Samoa');
postgres=# INSERT INTO Countries VALUES ('AD', 'Andorra');
postgres=# INSERT INTO Countries VALUES ('AO', 'Angola');
postgres=# INSERT INTO Countries VALUES ('AI', 'Anguilla');
postgres=# INSERT INTO Countries VALUES ('AQ', 'Antarctica');
postgres=# INSERT INTO Countries VALUES ('AG', 'Antigua And Barbuda');
postgres=# INSERT INTO Countries VALUES ('AR', 'Argentina');
postgres=# SELECT * FROM Countries;
countryid | countryname
-----------+---------------------
AL | Albania
DZ | Algeria
AS | American Samoa
AD | Andorra
AO | Angola
AI | Anguilla
AQ | Antarctica
AG | Antigua And Barbuda
AR | Argentina
(9 rows)
Retrieving data
test.php
-------------------------------------
// attempt a connection
$dbh = pg_connect("host= dbname=test user=postgres");
if (!$dbh) {
die("Error in connection: " . pg_last_error());
}
// execute query
$sql = "SELECT * FROM Countries";
$result = pg_query($dbh, $sql);
if (!$result) {
die("Error in SQL query: " . pg_last_error());
}
// iterate over result set
// print each row
while ($row = pg_fetch_array($result)) {
echo " $row[0] $row[1]
" ;
}
// free memory
pg_free_result($result);
// close connection
pg_close($dbh);
?>
上述测试来自:http://www.techrepublic.com/blog/howdoi/how-do-i-use-php-with-postgresql/110
运行
#php test.php
-------------------------------------
AL Albania
DZ Algeria
AS American Samoa
AD Andorra
AO Angola
AI Anguilla
AQ Antarctica
AG Antigua And Barbuda
AR Argentina
-------------------------------------
在浏览器中显示
-------------------------------------
AL Albania
DZ Algeria
AS American Samoa
AD Andorra
AO Angola
AI Anguilla
AQ Antarctica
AG Antigua And Barbuda
AR Argentina
-------------------------------------
总结
php连接考php支持;
如果想使用pgsql,编译的时候使用参数 --with-pgsql;
如果想使用pdo,编译的时候使用参数 --with-pdo-pgsql ;
lighttpd服务器使用php-cgi进行解析,所以要把php-cgi的绝对路径传给fastcgi.server中的"bin-path"
阅读(1705) | 评论(0) | 转发(0) |