Home php教程 php手册 PostgreSQL连接数据的方法和操作实例

PostgreSQL连接数据的方法和操作实例

May 24, 2016 pm 06:30 PM

<?php
$pg = @pg_connect("host=localhost user=postgres password=sa dbname=employes") or die("can&#39;t connect to database.");
$query = "select * from employes order by serial_no";
//$query="insert into employes values(10008,&#39;susan&#39;,&#39;1985-09-04&#39;,&#39;80&#39;,&#39;50&#39;)";
$result = @pg_query($pg, $query) or die("can&#39;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 "<table border=1>";
echo "<tr>";
echo "<td>serial_no</td>";
echo "<td>name</td>";
echo "<td>birthday</td>";
echo "</tr>";
for ($i = 0; $i < pg_num_rows($result); $i++) {
    $row = @pg_fetch_row($result) or die("can&#39;t fetch row from table.");
    $serial_no = $row[0];
    $name = $row[1];
    $birthday = $row[2];
    echo "<tr>";
    echo "<td>$serial_no</td>";
    echo "<td>$name</td>";
    echo "<td>$birthday</td>";
    echo "</tr>";
}
echo "</table>";
//实例二[pg_fetch_array]
//echo "<table border=1>";
//echo "<tr>";
//echo "<td>serial_no</td>";
//echo"<td>name</td>";
//echo"<td>birthday</td>";
//echo"</tr>";
//
//for($i=0;$i<pg_num_rows($result);$i++)
//{
//
//$row=@pg_fetch_array($result) or die("can&#39;t fetch row from table.");
//$serial_no= $row[&#39;serial_no&#39;];
//$name= $row[&#39;name&#39;];
//$birthday= $row[&#39;birthday&#39;];
//echo"<tr>";
//echo"<td>$serial_no</td>";
//echo"<td>$name</td>";
//echo"<td>$birthday</td>";
//echo"</tr>";
//
//}
//echo"</table>";
//增加,删除,修改实例
//$newrow=array("serial_no"=>"1006","name"=>"peter","birthday"=>"1990-07-03","salary"=>"90","bonus"=>"80");
//$reusult=@pg_insert($pg,"employes",$newrow) or die("can&#39;t insert data to table.");//开源代码phprm.com
//if($reusult)
//{
//echo "rechords inserted sucessfully!";
//}
//
pg_close($pg);
Copy after login


本文地址:

转载随意,但请附上文章地址:-)

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)