Settings
|
Sign in
|
Sign up
Bar
Post
Home
>
Bar PHP
>
View post
Reply the post
|
View all
The author has
64
posts.
First
Previous
1
2
3
4
5
6
7
Next
Last
今天我來系統地學習一下PDO
Floor 12
巨大八爪鱼
5/30/15 19:40
回復:10樓
DWCS3中自動生成的代碼就是這樣。
Floor 13
巨大八爪鱼
5/30/15 19:40
回復:11樓
以後一般情況下都採用這個代碼
Floor 14
巨大八爪鱼
5/30/15 19:42
接下來研究如何建立持久連接,這個我還從來沒學過。。。
Floor 15
巨大八爪鱼
5/30/15 19:43
PHP手冊上說,建立數據庫持久連接可以大幅度提高性能。
Floor 16
巨大八爪鱼
5/30/15 19:43
資料庫!
不是數據庫(大陸說法)!
Floor 17
巨大八爪鱼
5/30/15 19:57
$dbh = null;
這個相當於原來的mysql_close();
Floor 18
巨大八爪鱼
5/30/15 19:58
人家官方文檔都用$dbh,所以我也用$dbh吧。。。
Floor 19
巨大八爪鱼
5/30/15 20:01
try {
$dbh = new PDO("mysql:host=localhost;dbname=test", "php", DB_PW, array(PDO::ATTR_PERSISTENT => true));
} catch (PDOException $e) {
trigger_error($e->getMessage(), E_USER_ERROR);
}
// NO OUTPUT
Floor 20
巨大八爪鱼
5/30/15 20:05
PDO::ATTR_PERSISTENT
mysql:host=localhost;dbname=test
這兩個需要記住
Floor 21
巨大八爪鱼
5/30/15 20:53
獲取單條記錄
$id = (int)@$_GET["i"];
if ($id < 1) {
$id = 1;
}
$sql = "SELECT ItemName, ItemAddress FROM WiFiHotSpots WHERE ItemID = {$id}";
$stmt = $dbh->query($sql); // use $stmt instead of $rs or $result
$row = $stmt->fetch();
echo "<b>" . $row[0] . "</b>: " . $row["ItemAddress"];
輸出: 7th Brigade Park, Chermside: Delaware St
First
Previous
1
2
3
4
5
6
7
Next
Last
Content converter:
No conversion
Mainland
Taiwan
Hong Kong
Singapore
Reply the post
Content:
User:
You are currently anonymous.
Captcha:
Unclear? Try another one.