问题描述
目前,我正在使用用于 MysqL 的 azure 应用服务和 azure 数据库服务器进行编码。
执行'select'语句时,只返回'1'。
我不认为这是连接问题,因为“插入”语句工作正常。
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
中,然后使用 fetch 并填充结果变量和 Done