|
31樓 巨大八爪鱼
2015-5-30 21:22
$sql = "SELECT * FROM WiFiHotSpots WHERE ItemName = ? AND ItemID > 2"; 非变量可以直接写入数据库
|
|
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"] } ?>
|