二款PostgreSQL串連資料的方法和操作執行個體
二款postgresql串連資料的方法和操作執行個體.
$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); //輸出多少條記錄被查詢
//if($result)
//{
//echo "recrods inserted sucessfully!";
//echo pg_affected_rows($result);//輸出多少條記錄被插入
//}
//執行個體一[pg_fetch_row]
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];
$birthday= $row[2];
echo"
}
echo"
";echo "
";echo "
| serial_no | ";echo"
name | ";echo"
birthday | ";echo"
";
";echo"
| $serial_no | ";echo"
$name | ";echo"
$birthday | ";echo"
";
";
//執行個體二[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"
";
//增加,刪除,修改執行個體
//$newrow=array("serial_no"=>"1006","name"=>"peter","birthday"=>"1990-07-03","salary"=>"90","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.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/630835.htmlTechArticle二款PostgreSQL串連資料的方法和操作執行個體 二款postgresql串連資料的方法和操作執行個體. $pg=@pg_connect(host=localhost user=postgres password=sa dbname=employes)...