PDO
無痛使用:
$dsn = "mysql:host=$db_host;dbname=$db_name;charset=utf8";
$dbh = new PDO($dsn, $db_user, $db_password);
$dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sth=$dbh->prepare("INSERT INTO zh_tw_article (ImageURL,Topic) VALUES (:imageURL,:topic)");
while ($result = $sth->fetch(PDO::FETCH_OBJ))
{
echo $result->ArticleIndex . '-' . $result->Topic;
}
- http://easonyo.pixnet.net/blog/post/22966510-pdo-(php-data-object)-%E7%B0%A1%E6%98%93%E6%95%99%E5%AD%B8-
- http://blog.roga.tw/2010/06/%E6%B7%BA%E8%AB%87-php-mysql-php-mysqli-pdo-%E7%9A%84%E5%B7%AE%E7%95%B0/
- http://www.actman.tw/~blog/2010/11/php-%E4%BD%BF%E7%94%A8-pdo-%E5%AD%98%E5%8F%96%E8%B3%87%E6%96%99%E5%BA%AB%E4%B8%80%E5%AD%98%E5%8F%96%E6%AD%A5%E9%A9%9F%E8%88%87%E5%B8%B8%E7%94%A8%E5%8A%9F%E8%83%BD%E4%BB%8B%E7%B4%B9/
- http://phorum.study-area.org/index.php?topic=48055.0
-----------
bindParam and bindValue
bindParam會將一個PHP變數與SQL綁定,當變數變化時,SQL也會變動
bindValue則不會,只會執行最初綁定的值
沒有留言:
張貼留言