PHP connection and operation of PostgreSQL database method, PostgreSQL database
This article describes the PHP connection and operation of the PostgreSQL database method. Share to everyone for your reference.
The implementation method is as follows:
Copy the Code code as follows:
$PG = @pg_connect ("Host=localhost user=postgres password=sa Dbname=employes")
Or Die ("can ' t connect to database.");
$query = "SELECT * from Employes order by Serial_no";
$query = "INSERT into employes values (10008, ' Susan ', ' 1985-09-04 ', ' 80 ', ' 50 ')";
$result = @pg_query ($PG, $query) or Die ("can ' t run Query to table.");
echo pg_num_rows ($result); Output how many records are queried
if ($result)
//{
echo "Recrods inserted sucessfully!";
echo pg_affected_rows ($result);//Output How many records are inserted
//}
Example one [Pg_fetch_row]
echo "
"; echo "
"; echo "
Serial_no | "; Echo
Name | "; Echo
Birthday | "; Echo
"; For ($i =0, $i {$row = @pg_fetch_row ($result) or Die ("can ' t-fetch row from table.") $serial _no= $row [0]; $name = $row [1]; $birt Hday= $row [2]; Echo
"; Echo
$serial _no | "; Echo
$name | "; Echo
$birthday | "; Echo
"; } Echo
";
Example two [Pg_fetch_array]
echo "
"; echo "
"; echo "
Serial_no | "; Echo
Name | "; Echo
Birthday | "; Echo
"; For ($i =0, $i//{////$row = @pg_fetch_array ($result) or Die ("can ' t fetch row from table.");//$serial _no= $row [' Serial_ No ']; $name = $row [' name ']; $birthday = $row [' Birthday ']; Echo
"; Echo
$serial _no | "; Echo
$name | "; Echo
$birthday | "; Echo
"; }//echo "
";
Add, delete, modify instance
$newrow =array ("serial_no" = "1006", "name" and "Peter", "Birthday" and "1990-07-03", "salary" and "All", "bonus "=" 80 ");
$reusult = @pg_insert ($PG, "employes", $newrow) or Die ("can ' t insert data to table.");
if ($reusult)
//{
echo "Rechords inserted sucessfully!";
//}
//
Pg_close ($PG);
I hope this article is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/932488.html www.bkjia.com true http://www.bkjia.com/PHPjc/932488.html techarticle PHP Connection and operation of PostgreSQL database method, PostgreSQL database This article describes the PHP connection and operation of the PostgreSQL database method. Share to everyone for your reference. Concrete Reality ...