View Single Post
  #2   IP: 112.87.17.117
Old 2015-05-21, 07:22 AM
Napa Napa is offline
初级会员
 
Join Date: 2011-11-21
Posts: 1
Napa 现在声名狼藉
Default

Code:
<?php
//这种方法不错.
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");

if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

/* prepare statement */
if ($stmt = $mysqli->prepare("SELECT Code, Name FROM Country ORDER BY Name LIMIT 5")) {
    $stmt->execute();

    /* bind variables to prepared statement */
    $stmt->bind_result($col1, $col2);

    /* fetch values */
    while ($stmt->fetch()) {
        printf("%s %s\n", $col1, $col2);
    }

    /* close statement */
    $stmt->close();
}
/* close connection */
$mysqli->close();

?>
mysql_fetch_array

它打印两种方式:一种是关联数组;一种是索引数组

如果只需要一结果的话,别用它
Reply With Quote