以前一直使用mysql进行数据库连接,但是随着php的发展逐步由放弃mysql系列函数的趋势,改用mysqli系列函数,下面是一个使用mysqli进行数据库的demo:
<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>
以上就介绍了php使用mysqli连接数据库,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。