MySQL 查询在 azure 应用服务 + azure 数据库服务器中始终只返回“1”

崔正泰

目前,我正在使用用于 mysql 的 azure 应用程序服务和 azure 数据库服务器进行编码。

执行“select”语句时,只返回“1”。

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

这是我在 azure 应用服务上运行的 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; 

有什么问题?

方位角

这个脚本会帮助你

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获取并填充结果变量和完成

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章