您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
webman-配置數據庫-psql基本使用及php7.3.4中pgsql擴展安裝
发布时间:2022-01-31 21:04:12编辑:雪饮阅读()
上篇中使用psql命令連接了win10中所允許遠程連接的postgresql9.4服務端。
那麽psql命令行中使用sql語句還有一點注意點,就是我們之前在postgresql9.4中所建立的那個user表其實不是很標準,因爲postgresql中user是關鍵字。
若是自己創建的user表是在public架構中,此時若直接執行如select * from user則結果如:
webman=# select * from user;
current_user
--------------
postgres
(1 row)
這裏並沒有看到我們之前user表中的id和name字段,那麽當時user表中我們也有插入數據記錄的,所以這裏不可能不顯示結果的。
這裏顯示的應該就是系統關鍵字user的查詢結果。那麽如過要查看我們自己建立的那個user表,則查詢語句如:
webman=# select * from public.user;
id | name
----+------
1 | 雪飲
(1 row)
為php7.3.4安裝pgsql擴展
如果你php7.3.4的源代碼還在,在可以直接進入源代碼中ext/pgsql中進行編譯,我這裏源代碼找不到了,於是重新下載了,那麽解壓后我們進入源代碼中的ext/pgsql目錄中
cd /root/php-7.3.4/ext/pgsql
然後編譯如
./configure --with-php-config=/usr/local/php734/bin/php-config
make && make install
在make && make install過程中可能會遭遇:
/root/php-7.3.4/ext/pgsql/php_pgsql.h:35:22: fatal error: libpq-fe.h: No such file or directory
#include <libpq-fe.h>
^
compilation terminated.
make: *** [pgsql.lo] Error 1
這個錯誤
此時我們根據自己的情況搜索postgresql的yum包中包含dev的,根據你的環境酌情選擇要安裝的dev包
[root@localhost pgsql]# yum search postgresql | grep -i dev
postgresql-devel.i686 : PostgreSQL development header files and libraries
postgresql-devel.x86_64 : PostgreSQL development header files and libraries
postgresql10-devel.x86_64 : PostgreSQL development header files and libraries
postgresql11-devel.x86_64 : PostgreSQL development header files and libraries
postgresql12-devel.x86_64 : PostgreSQL development header files and libraries
postgresql13-devel.x86_64 : PostgreSQL development header files and libraries
postgresql14-devel.x86_64 : PostgreSQL development header files and libraries
postgresql96-devel.x86_64 : PostgreSQL development header files and libraries
rh-postgresql10-postgresql-devel.x86_64 : PostgreSQL development header files
rh-postgresql10-scldevel.x86_64 : Package shipping development files for
rh-postgresql12-postgresql-devel.x86_64 : PostgreSQL development header files
rh-postgresql12-scldevel.x86_64 : Package shipping development files for
rh-postgresql13-postgresql-devel.x86_64 : PostgreSQL development header files
rh-postgresql13-scldevel.x86_64 : Package shipping development files for
rh-postgresql95-postgresql-devel.x86_64 : PostgreSQL development header files
rh-postgresql95-scldevel.x86_64 : Package shipping development files for
rh-postgresql96-postgresql-devel.x86_64 : PostgreSQL development header files
rh-postgresql96-scldevel.x86_64 : Package shipping development files for
soci-postgresql-devel.x86_64 : PostGreSQL back-end for soci
libpq5-devel.x86_64 : Development files for building PostgreSQL client tools
postgresql-pgpool-II-devel.x86_64 : The development files for pgpool-II
我這裏選擇的是postgresql-devel.x86_64包,然後安裝postgresql-devel.x86_64包
yum install postgresql-devel.x86_64
安裝完成后再次make && make install
[root@localhost pgsql]# make && make install
/bin/sh /root/php-7.3.4/ext/pgsql/libtool --mode=compile cc -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -I. -I/root/php-7.3.4/ext/pgsql -DPHP_ATOM_INC -I/root/php-7.3.4/ext/pgsql/include -I/root/php-7.3.4/ext/pgsql/main -I/root/php-7.3.4/ext/pgsql -I/usr/local/php734/include/php -I/usr/local/php734/include/php/main -I/usr/local/php734/include/php/TSRM -I/usr/local/php734/include/php/Zend -I/usr/local/php734/include/php/ext -I/usr/local/php734/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /root/php-7.3.4/ext/pgsql/pgsql.c -o pgsql.lo
mkdir .libs
cc -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -I. -I/root/php-7.3.4/ext/pgsql -DPHP_ATOM_INC -I/root/php-7.3.4/ext/pgsql/include -I/root/php-7.3.4/ext/pgsql/main -I/root/php-7.3.4/ext/pgsql -I/usr/local/php734/include/php -I/usr/local/php734/include/php/main -I/usr/local/php734/include/php/TSRM -I/usr/local/php734/include/php/Zend -I/usr/local/php734/include/php/ext -I/usr/local/php734/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /root/php-7.3.4/ext/pgsql/pgsql.c -fPIC -DPIC -o .libs/pgsql.o
/bin/sh /root/php-7.3.4/ext/pgsql/libtool --mode=link cc -DPHP_ATOM_INC -I/root/php-7.3.4/ext/pgsql/include -I/root/php-7.3.4/ext/pgsql/main -I/root/php-7.3.4/ext/pgsql -I/usr/local/php734/include/php -I/usr/local/php734/include/php/main -I/usr/local/php734/include/php/TSRM -I/usr/local/php734/include/php/Zend -I/usr/local/php734/include/php/ext -I/usr/local/php734/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -o pgsql.la -export-dynamic -avoid-version -prefer-pic -module -rpath /root/php-7.3.4/ext/pgsql/modules pgsql.lo -Wl,-rpath,/usr/lib64 -L/usr/lib64 -lpq
cc -shared .libs/pgsql.o -L/usr/lib64 -lpq -Wl,-rpath -Wl,/usr/lib64 -Wl,-soname -Wl,pgsql.so -o .libs/pgsql.so
creating pgsql.la
(cd .libs && rm -f pgsql.la && ln -s ../pgsql.la pgsql.la)
/bin/sh /root/php-7.3.4/ext/pgsql/libtool --mode=install cp ./pgsql.la /root/php-7.3.4/ext/pgsql/modules
cp ./.libs/pgsql.so /root/php-7.3.4/ext/pgsql/modules/pgsql.so
cp ./.libs/pgsql.lai /root/php-7.3.4/ext/pgsql/modules/pgsql.la
PATH="$PATH:/sbin" ldconfig -n /root/php-7.3.4/ext/pgsql/modules
----------------------------------------------------------------------
Libraries have been installed in:
/root/php-7.3.4/ext/pgsql/modules
If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
- add LIBDIR to the `LD_LIBRARY_PATH' environment variable
during execution
- add LIBDIR to the `LD_RUN_PATH' environment variable
during linking
- use the `-Wl,--rpath -Wl,LIBDIR' linker flag
- have your system administrator add LIBDIR to `/etc/ld.so.conf'
See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
Build complete.
Don't forget to run 'make test'.
Installing shared extensions: /usr/local/php734/lib/php/extensions/no-debug-non-zts-20180731/
按照make && make install后的提示,我們可以找到編譯出來的pgsql.so路徑/usr/local/php734/lib/php/extensions/no-debug-non-zts-20180731/pgsql.so
配置到php.ini中
[root@localhost pgsql]# cat /usr/local/php734/lib/php.ini | grep -i /usr/local/php734/lib/php/extensions/no-debug-non-zts-20180731/pgsql.so
extension=/usr/local/php734/lib/php/extensions/no-debug-non-zts-20180731/pgsql.so
再次確認pgsql擴展已安裝成功
[root@localhost pgsql]# /usr/local/php734/bin/php -c /usr/local/php734/lib/php.ini -m | grep -i pgsql
pgsql
关键字词:webman,配置,數據庫,psql,基本,使用,php7.3.4,pgsql,擴展,安裝