於是在連線前,你需要去安裝 Postgresql應用程式for Windiws or Linux
安裝完後請務必在install應用程式後接著安裝Apache和phpPgAdmin
之後開啟 localhost:8080/phpPgAdmin就可以看到資料庫了! ,如果打不開就開啟
之後網際網路瀏覽器會出現Postgresql的登入,只需要輸入 帳號: postgres 密碼: *安裝時設定的
,就能登入。
之後新增databae之後選擇 schemas 的 public ,並且新增一個資料表我在此不是新增 ic 是 ttl
然後放入幾筆資料:
之後PHP的連線程式碼是:
<!DOCTYPE html>
<html>
<head>
<title>7805ic</title>
</head>
<body style="font-family:'微軟正黑體'">
7805同系列的IC有:
<br><br>
取自Postgresql:
<?php
$link = pg_connect("host=localhost port=5432 dbname=7805ic user=postgres password=root");
if(!$link) die("伺服器已掛,自己的伺服器自己救!");
$result = pg_query($link,"select * from ttl") or die("伺服器已掛!");
echo "<br>";
while($row = pg_fetch_row($result)){
echo $row[0];
echo "<br>";
}
pg_close($link);
?>
</body>
</html>
然後應該會看到:
居然還記得穩壓IC型號 :)
進階參考:
php.net pg: http://php.net/manual/en/function.pg-connect.php
之後會看看sqlite跟perpared statement(PDO)


沒有留言:
張貼留言