mysqli的预处理功能使用

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
云数据库 RDS MySQL Serverless,价值2615元额度,1个月
简介: 1 2 3 4 查询剩余羽绒服信息 5 6 7 8 9 10 11 12 13 输入要查询的品牌14 15 16 输入要查询的货号17 18...
 1 <html>
2 <head>
3 <meta http-equiv="Content-Type" content="text/html; charset=GB2312">
4 <title> 查询剩余羽绒服信息 </title>
5
6 <!-- <script language = "javascript" src = "../js/goods_info_js.js"></script> -->
7 <link type = "text/css" rel = "stylesheet" href = "../css/goods_css.css">
8 </head>
9 <body onload = "javascript:goods_search_show()">
10 <form action = "http://localhost:8088/zzb/sole/php/goods_search_php.php" method = "post">
11 <div>
12 <div id = "goods_name">
13 输入要查询的品牌<input type = "text" name = "goods_name_input" />
14 </div>
15 <div id = "goods_number">
16 输入要查询的货号<input type = "text" name = "goods_number_input" />
17 </div>
18
19 <div>
20 <input type = "submit" name = "goods_submit" value = "确定"/>
21 </div>
22 </div>
23 </form>
24
25
26 </body>
27 </html>

goods_search_php.php

 1 <?php
2 include "D:\AppServ\www\zzb\sole\php\sql.init.php";
3 echo '<pre>';
4 print_r($_POST);
5 echo '</pre>';
6 /*
7 mysql> desc goods_info;
8 +---------------+-------------+------+-----+---------+----------------+
9 | Field | Type | Null | Key | Default | Extra |
10 +---------------+-------------+------+-----+---------+----------------+
11 | goods_id | int(11) | NO | PRI | NULL | auto_increment |
12 | goods_name | varchar(30) | YES | | NULL | |
13 | goods_number | varchar(10) | YES | | NULL | |
14 | goods_color | varchar(10) | YES | | NULL | |
15 | goods_size | varchar(10) | YES | | NULL | |
16 | goods_left | int(11) | YES | | NULL | |
17 | goods_date | datetime | YES | | NULL | |
18 | goods_comment | text | YES | | NULL | |
19 +---------------+-------------+------+-----+---------+----------------+
20 */
21
22 //$stmt = $link->stmt_init();
23 $sql = "select goods_name,goods_number, goods_color, goods_size, goods_left,goods_date,goods_comment from goods_info where goods_name=? and goods_number=?";
24     $stmt = $link->prepare($sql);
25 $type = "ss";
26 $stmt->bind_param($type,$_POST[goods_name_input],$_POST[goods_number_input]);
27 $stmt->execute();
28 //$stmt->store_result();//用于多个查询语句
29 $stmt->bind_result($goods_name,$goods_number,$goods_color,$goods_size,$goods_left,$goods_date,$goods_comment);
30
31 echo "<table align = 'center' border = '1'>";
32 echo "<tr><th>衣服品牌</th><th>货号</th><th>颜色</th><th>大小</th><th>剩余数量</th><th>进货日期</th><th>备注</th></tr>";
33 while($stmt->fetch())
34 {
35 echo "<tr>";
36 echo "<th>{$goods_name}</th>";
37 echo "<th>{$goods_number}</th>";
38 echo "<th>{$goods_color}</th>";
39 echo "<th>{$goods_size}</th>";
40 echo "<th>{$goods_left}</th>";
41 echo "<th>{$goods_date}</th>";
42 echo "<th>{$goods_comment}</th>";
43 echo "</tr>";
44
45 }
46 echo '</table>';
47
48 $stmt->close();
49 $link->close();
  1. 注意$stmt的得到方式
  2. 注意绑定形参、执行语句、绑定结果这三者的顺序
  3. 注意可直接将获得的表单内容传入到参数绑定语句中

sql_init.php

1 <?php
2
3 $link = new mysqli("localhost","root","a123","sole") or die("连接失败!");



相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
2月前
|
编译器 程序员 Linux
C++系列九:预处理功能
C++系列九:预处理功能
|
5月前
|
SQL 存储 关系型数据库
MySQL - 动态SQL与预处理语句
MySQL - 动态SQL与预处理语句
48 0
|
SQL 安全 关系型数据库
PDO 预处理|学习笔记
快速学习 PDO 预处理,本节学习PDO的预处理。与事务相同并不是PDO的功能,本节介绍PDO如何实现预处理。
205 0
PDO 预处理|学习笔记
|
关系型数据库 MySQL 数据库连接
PDO 预处理数据绑定|学习笔记
快速学习 PDO 预处理数据绑定,PDO预处理数据绑定有多种方式。
218 0
PDO 预处理数据绑定|学习笔记
|
PHP 数据库 开发者
PDO 操作学习路径|学习笔记
快速学习 PDO 操作学习路径
67 0
|
PHP 开发者
PDO 异常学习路径|学习笔记
快速学习 PDO 异常学习路径
42 0
|
SQL PHP 数据库
PDO 学习路径|学习笔记
快速学习 PDO 学习路径
58 0
|
SQL PHP 开发者
封装 PDO(写操作)|学习笔记
快速学习封装 PDO(写操作)
49 0