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 fetch array の使用方法を知りたい

$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 に答える