- 论坛徽章:
- 0
|
我用来连接POSTGRE的例子:
<?php
echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">';
$host='xxx.xxx.xxx.xxx';
$port='5432';
$dbname='*****';
$user='*****';
$password='************';
$conn_string1 = "pgsql:host=$host; dbname=$dbname; user=$user;port=$port; password=$password";
$myconn=& new pdo($conn_string1) or die("Could not connect");
$sql='select * from cptzmx';
$stmt=$myconn->prepare($sql);
try {
$stmt->bindColumn(1, $name);
$stmt->bindColumn(2, $colour);
$stmt->execute();
while ($row = $stmt->fetch(PDO::FETCH_BOUND)) {
$data = $name . "\t" . $colour . "\t" ;
print $data;
}
}
catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "<br/>";
die();}
$myconn =null;
?> |
|