0

目前,我正在使用 azure app service 和 azure database server for mysql 进行编码。

当执行'select'语句时,只返回'1'。

我认为这不是连接问题,因为“插入”语句工作正常。

这是我在 azure app 服务上运行的 php 代码。

error_reporting(E_ALL); 
ini_set('display_errors',1); 
include('dbconnectr.php'); 

$id = $_GET['id'];
$stmt = $con->prepare('select * from contents where id='.$id);
$stmt->execute();
$result = $stmt->fetch();
echo $result; 

问题是什么?

4

1 回答 1

0

这个脚本会帮助你

error_reporting(E_ALL); 
ini_set('display_errors',1); 
include('dbconnectr.php'); 

$id = $_GET['id'];

$stmt = $con->prepare("select * from contents where id=?");

/* bind parameters */
$stmt->bind_param("i", $id);

/* execute query */
$stmt->execute();

/* bind result variables */
$stmt->bind_result($result);

/* fetch value */
$stmt->fetch();

print_r($result);

我使用绑定来保护自己免受 sql 注入。
所以我使用bind_param绑定参数,然后使用execute执行命令,然后绑定结果,然后bind_result使用获取并填充结果变量并完成

于 2021-03-19T16:20:35.113 回答