Two methods and operating examples of PostgreSQL connection data
Two methods and operational examples of PostgreSQL connection data.
$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 "
for ($i =0; $i<>
{
$row = @pg_fetch_row ($result) or Die ("can ' t fetch the row from table.");
$serial _no= $row [0];
$name = $row [1];
$birthday = $row [2];
Echo
}
Echo
"; Echo"
"; Echo"
Serial_no | "; Echo"
Name | "; Echo"
Birthday | "; Echo"
";
"; Echo"
$serial _no | "; Echo"
$name | "; Echo"
$birthday | "; 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);
http://www.bkjia.com/PHPjc/630835.html www.bkjia.com true http://www.bkjia.com/PHPjc/630835.html techarticle two methods and operating examples of PostgreSQL connection data two methods and operational examples of PostgreSQL connection data. $PG = @pg_connect (host=localhost user=postgres Password=sa Dbname=employes) ...