为什么echo在php中的SQL查询之后不返回ID?
我在一些php中有以下代码:为什么echo在php中的SQL查询之后不返回ID?,php,sql,mysqli,Php,Sql,Mysqli,我在一些php中有以下代码: $stmt = $connection->prepare("SELECT * FROM users where email = ?"); $stmt->bind_param('s', $email); if($stmt->execute()){ $result = $stmt->get_result(); $isUserFound = $result->num_rows == 1; if(isUserFound)
$stmt = $connection->prepare("SELECT * FROM users where email = ?");
$stmt->bind_param('s', $email);
if($stmt->execute()){
$result = $stmt->get_result();
$isUserFound = $result->num_rows == 1;
if(isUserFound){
$row = $result->fetch_row();
echo "<br>id: " . $row["id"];
}
$stmt=$connection->prepare(“从电子邮件=?”的用户中选择*”;
$stmt->bind_param('s',$email);
如果($stmt->execute()){
$result=$stmt->get_result();
$isUserFound=$result->num_rows==1;
if(isUserFound){
$row=$result->fetch_row();
回显“
id:”.$row[“id”];
}
我知道用户被找到是因为第二个if中的代码执行,我也做了手动检查以确保。我使用的语法是否有问题?即使用户存在,echo也只返回“id:”而不返回数据库中的id
我曾尝试对id使用单引号,也尝试使用大写字母,但均不返回任何内容。根据,fetch_row()
用于“将结果行作为枚举数组获取”。这将生成如下数组:
$row = [
0 => "2342",
1 => "user@example.com",
2 => "User",
];
相反,它将“作为关联数组获取结果行”,并提供如下内容:
$row = [
"id" => "2342",
"email" => "user@example.com",
"name" => "User",
];
请注意,如果您在开发环境中,您可能会看到“未定义索引”通知,这些通知可能会帮助您解决此问题。根据,fetch_row()
用于“将结果行作为枚举数组获取”。这将产生如下数组:
$row = [
0 => "2342",
1 => "user@example.com",
2 => "User",
];
相反,它将“作为关联数组获取结果行”,并提供如下内容:
$row = [
"id" => "2342",
"email" => "user@example.com",
"name" => "User",
];
请注意,如果您在您的开发环境中,您可能会看到“未定义索引”通知,这些通知可能会帮助您解决此问题。尝试
fetch\u assoc()
而不是fetch\u row()
,如果您发布为答案,则答案将标记为这样。感谢您如此快速地尝试fetch\u assoc()
而不是fetch\u row()
这很有效,如果您发布为,答案将标记为。谢谢您这么快