php 操作postgresql

<?php
# $id = $_GET['id'];  
# $db = pg_connect("host=localhost dbname=test user=postgres password=test");  
# $query = 'SELECT * FROM test where id='.$id;  
# $result = pg_query($query) or die('Query failed: ' . pg_last_error());  
# echo "<table>\n";  
# while ($line = pg_fetch_array($result, null, PGSQL_ASSOC)) {  
#     echo "\t<tr>\n";  
#     foreach ($line as $col_value) {  
#         echo "\t\t<td>$col_value</td>\n";  
#     }  
#     echo "\t</tr>\n";  
# }  
#  
# echo "</table>\n";  
# pg_free_result($result);  
# pg_close($db);  

if(isset($_GET['id'])){
	$id=$_GET['id'];
	
}else{
	
	$id=1;
}

$db=pg_connect("host=192.168.1.105  dbname=test  user=postgres  password=test");

$query='select *  from test where  id='.$id;

echo "<hr/>";
echo 'id=';
echo "<br/>";
echo 'id='.$id;
echo "<br/>";
echo $query;
echo "<hr/>";
$result=pg_query($query) or die('Query  failed:'.pg_last_error());
echo "<table>\n";
while ($line=pg_fetch_array($result,null,PGSQL_ASSOC)){
	echo "\t <tr>\n";
	foreach ($line as $col_value) {
		echo "\t\t<td>$col_value</td>\n";  
		
	}
	echo "\t</tr>\n"; 
	
}
echo "</table>\n";  
pg_free_result($result);
pg_close($db);

?>
[size=x-small][/size]

你可能感兴趣的:(PHP,PostgreSQL)