Use AdoDB coupled Postgres

xiaoxiao2021-03-06  20

In Linux, PHP and Postgres is a tool that is often used, how to make PHP connections to the Postgres backend database is a problem that needs to be resolved in the development website. This article tells you how to use the AdoDB function to join ;

First, please install Postgres:

In Debian, the installation is very simple: $> APT-GET Install PSQL can install Postgres in your computer;

Install Apace2: $> APT-GET Install Apache2;

Install PHP: $> APT-GET Install PHP;

Start PSQL in the terminal:

$> SU; log in with a super user;

$ su postgres; login to postgres

$> createdb mytest; create a database mytest;

$> psql mytest; /// Open PSQL;

Mytest # Create Table Test1 (XH Serial Primary Key,

KHDM VARCHAR (10),

Cpjg Numeric (10, 4) Check (cpjg> 0),

Kssj Date Not Null,

JSJ Date Not Null,

Check (jssj> kssj);

Use the above command to create your TEST data sheet;

Or use the VI, build the above command, Test.SQL file; then use

Mytest # / i test.sql

Command introduces your SQL statement; set up a data sheet;

Now you can add data in your data sheet;

Add data, you can grant this data sheet access to TEST users:

Mytest # create user test password 'test';

Mytest # Grant Insert, Update, Delete, SELECT On Test1 To Test;

Then use the VI or Emacs or Bluefish to establish as follows, name mytest1.php, save it in / var / wwwapache2-default / directory;

INCLUDE ('/ usr / share / adodb / adodb.inc.php');

$ db = adonewconnection ('posgres'); # EG 'mysql' or 'postgres'

/ * $ db-> debug = true; * /

$ Server = 'xxx.com';

$ USER = 'Test';

$ Database = 'mytest';

$ Password = 'Test';

$ DB-> Connect ($ Server, $ User, $ Password, $ Database);

$ r = $ dB-> execute ('select * from test');

Print_R ($ RS);

$ dB-> close ();

?>

Now you open your browser, enter http://mycompute/apache2-default/mytest1.php;

What should you see you in the TEST table;

Note: Modify the httpd.conf file to support PHP and modify the pg_hba.conf file to enable the 80-port to access Postgres. This article is not introduced, please find the relevant document.

转载请注明原文地址:https://www.9cbs.com/read-39856.html

New Post(0)