gpt4 book ai didi

php - 如何在使用 mysqli prepare 时获取 assoc 数组

转载 作者:可可西里 更新时间:2023-11-01 07:45:45 25 4
gpt4 key购买 nike

为了确保我的数据库安全,我使用了准备语句。这是我的代码:

//connecting to MySql database
$con=mysqli_connect("host","user","pass","dbname");
// checking database connection
if (mysqli_connect_errno($con)){
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$stmt = mysqli_prepare($con,"SELECT * FROM `table` WHERE emb=? LIMIT 1");
mysqli_stmt_bind_param($stmt, 's', $emb);
mysqli_stmt_execute($stmt);
mysqli_stmt_close($stmt);

现在我想知道如何使用 ASSOC 获取数组

$embInfo = mysqli_fetch_array($stmt, MYSQLI_ASSOC);

我想要这个,这样我就可以像下面这样放一些东西来获取值

$embInfo['name']

$embInfo['email']

最佳答案

试试这个:

//connecting to MySql database
$con=mysqli_connect("host","user","pass","dbname");
// checking database connection
if (mysqli_connect_errno($con)){
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$stmt = mysqli_prepare($con,"SELECT * FROM `table` WHERE emb=? LIMIT 1");
mysqli_stmt_bind_param($stmt, 's', $emb);
mysqli_stmt_execute($stmt);


while($embInfo = mysqli_fetch_array($stmt, MYSQLI_ASSOC)){
echo 'My name is '.$embInfo['name'].'and my email is '.$embInfo['email'].'<br/>';

}

mysqli_stmt_close($stmt);

关于php - 如何在使用 mysqli prepare 时获取 assoc 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18688611/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com