「PHP接入SQL」:修訂間差異
跳至導覽
跳至搜尋
Stanleyliu(留言 | 貢獻) |
Stanleyliu(留言 | 貢獻) |
||
| 第11行: | 第11行: | ||
$sth->bindParam(':SN',$SN); | $sth->bindParam(':SN',$SN); | ||
$sth->execute(); | $sth->execute(); | ||
</ | </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]); | ||
於 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"];
}