|
32樓 巨大八爪鱼
2015-5-30 21:22
|
|
33樓 巨大八爪鱼
2015-5-30 21:28
不過這樣的話,就無法得到生成的SQL字符串了。。。
|
|
34樓 巨大八爪鱼
2015-5-30 21:30
$address = "Delaware St";
$sql = "SELECT * FROM WiFiHotSpots WHERE ItemName = ? AND ItemID < 15 AND ItemAddress = ?"; $stmt = $dbh->prepare($sql); $stmt->execute(array($name, $address)); $row = $stmt->fetch(); echo "(" . $row["ItemLatitude"] . ", " . $row["ItemLongitude"] . ")";
|
|
35樓 巨大八爪鱼
2015-5-30 21:38
判斷記錄集是否為空: if (!$stmt->rowCount()) { echo "記錄集為空"; }
|
|
36樓 巨大八爪鱼
2015-5-30 21:39
$stmt->rowCount()可以直接當布爾值用。
|
|
37樓 巨大八爪鱼
2015-5-30 21:41
原始方法: if (mysql_num_rows($rs) == 0) { echo "記錄集為空"; }
|
|
38樓 巨大八爪鱼
2015-5-30 21:46
|
|
39樓 巨大八爪鱼
2015-5-30 21:49
Error
SQL query:
SELECT * FROM WiFiHotSpots WHERE ItemName = ? AND ItemID < 15 AND ItemAddress = ?
LIMIT 0, 25
MySQL said:
#1064 - You have an error in your SQL syntax; check the manual that
corresponds to your MariaDB server version for the right syntax to use
near '? AND ItemID < 15 AND ItemAddress = ?
LIMIT 0, 25' at line 1
|
|
40樓 巨大八爪鱼
2015-5-30 22:07
bindColumn的用法: <?php include_once("conn.php");
$sql = "SELECT * FROM WiFiHotSpots"; $stmt = $dbh->prepare($sql); $stmt->execute();
$stmt->bindColumn("ItemSuburb", $suburb); foreach ($stmt as $row) { echo $suburb . "<br>"; // $suburb is equivalent to $row["ItemSuburb"] } ?>
|
|
41樓 巨大八爪鱼
2015-5-30 22:08
bindColumn將一個字段綁定到一個php變量中,也就是每次循環自動執行: $suburb = $row["ItemSuburb"]
|