4

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

//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']
4

2 回答 2

-1

尝试这个:

//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);
于 2014-03-02T23:02:59.873 回答
-3

我可以建议一个替代方案吗

{
  $server = '';
  $user = '';
  $pass = '';
  $db = '';

  // connect to the database
  $mysqli = new mysqli($server, $user, $pass, $db);

  // show errors (remove this line if on a live site)
  mysqli_report(MYSQLI_REPORT_ERROR);

  $club=$_POST'club'];
  $sql = "SELECT * FROM players WHERE club = '$club'";
  $result=mysqli_query($mysqli,$sql);
  while($row = mysqli_fetch_array($result))
  {
    echo $row['player'];
  }
  }
于 2013-09-08T21:17:10.993 回答