English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
不多说,请看代码:
<table width="100%" border="1" cellpadding="0" cellspacing="0"> tr> <td>代号</td> <td>姓名</td> <td>性别</td> <td>民族</td> <td>生日</td> </tr> <?php 1.创建一个mysqli对象,创建连接对象 $db = new MySQLi("localhost","username","password","database_name"); 2.准备一条SQL语句 $sql = "select * from info"; 3.执行SQL语句,如果是查询语句,成功返回结果集对象 $reslut = $db->query($sql); 4.判断返回是否执行成功 if($reslut { while($attr = $reslut->fetch_row()) { echo "<tr> <td>{$attr[0]}</td> <td>{$attr[1]}<//td> <td>{$attr[2]}<//td> <td>{$attr[3]}<//td> <td>{$attr[4]}<//td> </tr>"; } } ?> </table>
fetch_all() Returns the entire array
fetch_row() Returns an indexed array
fetch_assoc() Returns an associated array
fetch_object() Returns an object
fetch_array() Returns an array with both indexed and associated
Database deletion, addition, and modification operations
<?php //Create connection object $db = new MySQLi("localhost","username","password","database_name"); //Prepare SQL statement $sql = "delete from info where code='p004'"; Delete //$sql = "insert course values" Add //$sql = "update table_name set field=value where field=value" Modify //Execute SQL statement $r = $db->query($sql); if($r) { echo "Execution successful"; } else { echo "Execution failed"; } ?>
That's all for this article. I hope the content of this article can bring you some help in learning or work, and I also hope to support the呐喊 tutorial more!
Statement: The content of this article is from the network, the copyright belongs to the original author. The content is contributed and uploaded by Internet users spontaneously. This website does not own the copyright, has not been manually edited, and does not assume relevant legal liability. If you find any suspected copyright content, please send an email to: notice#oldtoolbag.com (When reporting via email, please replace # with @) to report, and provide relevant evidence. Once verified, this site will immediately delete the suspected infringing content.