Home > Backend Development > PHP Tutorial > php pdo connects to MySQL database

php pdo connects to MySQL database

WBOY
Release: 2016-07-29 08:49:53
Original
1188 people have browsed it

<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>
Copy after login
').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

The above introduces how to use php pdo to connect to a MySQL database, including the Mysql database and the content of connecting to MySql. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template