Home>Article>Backend Development> Detailed explanation of the basic operation code for calling MySQL database in PHP
This article mainly talks about the basic operation codes and explanations for calling MySQL database in PHP. It has certain reference value. Friends in need must take a good look!
##PHP-MySQL basic operation
2"; // 查询正序(asc)倒序(desc) $selectDataSql12 = "select * from lee01 order by id asc"; // 分页查询 (limit 下标,查询数量) $selectDataSql13 = "select * from lee01 order by `index` asc limit 0,2"; $selectDataSql14 = "select * from lee01 order by `index` asc limit 2,2"; $selectDataSql15 = "select * from lee01 order by `index` asc limit 4,2"; // 删除数据表 $dropTableSql = "drop table lee01"; // 清空数据表(同时删除自增字段的定义) $truncateTableSql1 = "truncate table lee01"; // 清空数据表(删除表中的所有行,一行一行的删)(delete 保留原有自增字段,再次创建不占用删除字段) $deleteTableSql1 = "delete from lee01"; // 按条件删除 delete from 表名 [where条件] [order排序] [limit限定](删除范围数据可能会用到order、limit) $deleteTableSql2 = "delete from lee01 where phone = '用户名'"; // 修改数据(无条件全改) $updateSetSql = "update lee01 set name = 'ProsperLee',age=23 where id = '87654321'"; // 使用数据库 mysqli_select_db($conn, 'ProsperLee01'); // 使用数据库 // 3.设置通信编码 mysqli_query($conn, "set names utf8"); // 执行sql语句 $result = mysqli_query($conn, $selectDataSql1); var_dump($result); /** * fetch_assoc() 每次拿1条数据 * fetch_all() 拿出全部数据 */ $showData = $result->fetch_all(); var_dump($showData); // 关闭数据库 mysqli_close($conn);If you want to learn PHP without taking any detours, just follow the PHP Chinese website for more
PHP related tutorials,mysql related tutorialsare waiting for you to learn!
The above is the detailed content of Detailed explanation of the basic operation code for calling MySQL database in PHP. For more information, please follow other related articles on the PHP Chinese website!