Home > Backend Development > PHP Tutorial > PHP connects to MySQL to perform add, delete, modify and query operations

PHP connects to MySQL to perform add, delete, modify and query operations

高洛峰
Release: 2023-03-05 21:56:02
Original
1556 people have browsed it

This article mainly introduces the method of PHP connecting to MySQL to perform add, delete, modify and query operations. It has a very good reference value. Let’s take a look at it with the editor.

Not much to say Please look at the code:


# , ,


# Fetch_all () Back to all arrays

# FETCH_ROW ()

# FETCH_ASSOC () Return to the associated array

FETCH_OBJECT () Return to the object

# FETCH_ARAY () The array of arrays returned has both indexes and associated

steals Delete, add, and modify operations


<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","用户名","密码","数据库名");
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>
Copy after login

For more articles related to PHP connecting to MySQL for add, delete, modify, and check operations, please pay attention to the PHP Chinese website!


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