|
|
|
[PHP] ใครรู้วิธีเชื่อมต่อ PHP กับฐานข้อมูล PostgreSQLไมคะ |
|
|
|
|
|
|
|
Code (PHP)
<?php
$host = "host=127.0.0.1";
$port = "port=5432";
$dbname = "dbname=testdb";
$credentials = "user=postgres password=pass123";
$db = pg_connect( "$host $port $dbname $credentials" );
if(!$db){
echo "Error : Unable to open database\n";
} else {
echo "Opened database successfully\n";
}
$sql =<<<EOF
CREATE TABLE COMPANY
(ID INT PRIMARY KEY NOT NULL,
NAME TEXT NOT NULL,
AGE INT NOT NULL,
ADDRESS CHAR(50),
SALARY REAL);
EOF;
$ret = pg_query($db, $sql);
if(!$ret){
echo pg_last_error($db);
} else {
echo "Table created successfully\n";
}
pg_close($db);
?>
แปลงให้เป็น JSON นะครับ
|
|
|
|
|
Date :
2016-10-07 17:54:33 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|