「PHP接入SQL」:修訂間差異

出自TSK WIKI
跳至導覽 跳至搜尋
Root​(留言 | 貢獻)
Stanleyliu​(留言 | 貢獻)
 
(未顯示同一使用者於中間所作的 1 次修訂)
第1行: 第1行:
==PDO==
==PDO==
<php>
<syntaxhighlight lang="php" line>
define('DB_NAME','test');
define('DB_NAME','test');
define('DB_USER','test');
define('DB_USER','test');
第11行: 第11行:
$sth->bindParam(':SN',$SN);
$sth->bindParam(':SN',$SN);
$sth->execute();
$sth->execute();
</php>
</syntaxhighlight>
<php>
<syntaxhighlight lang="php" line>
$sth = $dbh->prepare('select * from db where SN = :SN');
$sth = $dbh->prepare('select * from db where SN = :SN');
$sth->bindParam(':SN',$value[SN]);
$sth->bindParam(':SN',$value[SN]);
第20行: 第20行:
echo $meta["name"];
echo $meta["name"];
}
}
</php>
</syntaxhighlight>

於 2024年10月30日 (三) 10:04 的最新修訂

PDO

define('DB_NAME','test');
define('DB_USER','test');
define('DB_PASSWD','test');
define('DB_HOST','localhost');
define('DB_TYPE','mysql');
$dbh = new PDO(DB_TYPE.':host='.DB_HOST.';dbname='.DB_NAME, DB_USER, DB_PASSWD);
$sth = $dbh->prepare('update db set zh_CN= :str where SN=:SN');
$sth->bindParam(':str',$str,PDO::PARAM_STR,12);
$sth->bindParam(':SN',$SN);
$sth->execute();
$sth = $dbh->prepare('select * from db where SN = :SN');
$sth->bindParam(':SN',$value[SN]);
$sth->execute();
while($meta = $sth->fetch(PDO::FETCH_ASSOC))
{
	echo $meta["name"];
}