Home > Backend Development > PHP Tutorial > php and mysql connection

php and mysql connection

WBOY
Release: 2016-07-29 09:07:03
Original
1026 people have browsed it

<code><span>$db_host</span>=<span>'localhost'</span>;   <span>//数据库主机</span><span>$db_database</span>=<span>'test'</span>;   <span>//数据库名</span><span>$db_username</span>=<span>'root'</span>;   <span>//账户名</span><span>$db_password</span>=<span>''</span>;   <span>//密码</span><span>$connection</span>=mysql_connect(<span>$db_host</span>,<span>$db_username</span>,<span>$db_password</span>);<span>//连接到数据库</span>
mysql_query(<span>"set names 'utf8'"</span>);<span>//编码转化</span><span>if</span>(!<span>$connection</span>){
<span>die</span>(<span>"could not connect to the database:</br>"</span>.mysql_error());<span>//诊断连接错误</span>}
<span>$db_selecct</span>=mysql_select_db(<span>$db_database</span>);<span>//选择数据库</span><span>if</span>(!<span>$db_selecct</span>)
{
<span>die</span>(<span>"could not to the database</br>"</span>.mysql_error());
}
<span>$query</span>=<span>"select * from eload_category "</span>;<span>//构建查询语句</span><span>$result</span>=mysql_query(<span>$query</span>);<span>//执行查询</span><span>if</span>(!<span>$result</span>)
{
<span>die</span>(<span>"could not to the database</br>"</span>.mysql_error());
}

print_r(mysql_fetch_array(<span>$result</span>));</code>
Copy after login

The result of using mysql_query cannot be output directly, and Resource id #4 will be printed.
Use mysql_fetch_array to convert into an array for output

').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

The above introduces the connection between php and mysql, including the relevant content. 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