以前一直使用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教程有興趣的朋友有幫助。