PHP uses mysqli to connect to the database

WBOY
Release: 2016-08-08 09:23:55
Original
1043 people have browsed it

Mysql has been used for database connection in the past, but with the development of PHP, it has gradually abandoned the trend of mysql series functions and switched to mysqli series functions. Here is a demo using mysqli for database:

<code><span>$conn</span> = mysqli_connect(<span>'localhost'</span>, <span>'root'</span>, <span>''</span>, <span>'addressBook'</span>) or die(<span>'Connect error!'</span>);

        <span>$sql</span> = <span>"insert into "</span>.<span>$this</span>->tb_group.<span>" value('', '<span>$name</span>', '<span>$pwd</span>', '<span>$numIdList</span>')"</span>;

        <span>$result</span> = <span>$conn</span>->query(<span>$sql</span>);        //添加成功result的值为boolean值<span>true</span>
        //<span>$result</span> = mysqli_query(<span>$conn</span>, <span>$sql</span>);

        <span>if</span> (<span>$result</span>) {
            <span>$lastid</span> = mysqli_insert_id(<span>$conn</span>);    //刚刚插入数据库的记录id
            <span>echo</span><span>"<BR>新建通讯录成功!"</span>;
        }<span>else</span>{
            <span>echo</span><span>"<BR>新建通讯录失败!"</span>;
        }</code>
Copy after login

The above introduces how PHP uses mysqli to connect to the database, including the relevant aspects. 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!