首頁 >後端開發 >php教程 >php pdo 連接MySQL資料庫

php pdo 連接MySQL資料庫

WBOY
WBOY原創
2016-07-29 08:49:531212瀏覽

<code><span><span><?php</span><span>$dbhost</span> =<span>"localhost"</span>;
<span>$dbuser</span> = <span>"root"</span>;
<span>$dbpwd</span> = <span>"123"</span>;
<span>$dbname</span> = <span>"mydatabase"</span>;
<span>$charName</span> = <span>"utf8"</span>;

<span>try</span> {
    <span>$conn</span> = <span>new</span> PDO(<span>"mysql:host=$dbhost;port=3306;dbname=$dbname"</span>, <span>$dbuser</span>, <span>$dbpwd</span>, <span>array</span>(PDO::MYSQL_ATTR_INIT_COMMAND => <span>"set names utf8"</span>));
    <span>//echo "数据库链接成功!"; </span>
}
<span>catch</span>(PDOException <span>$e</span>){
    <span>echo</span><span>$e</span>->getMessage();
}
<span>?></span></span></span></code>
').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

以上就介紹了php pdo 連接MySQL資料庫,包括了Mysql資料庫,連接MySql方面的內容,希望對PHP教學有興趣的朋友有幫助。

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn