PHP mysqli_stmt_bind_result MySQLi 函数

时间:2025-03-25 07:54:08
  • $link mysqli_connect("localhost""my_user""my_password""world");
  • /* check connection */
  • if (!$link) {
  •     printf("Connect failed: %s\n"mysqli_connect_error());
  •     exit();
  • }
  • /* prepare statement */
  • if ($stmt mysqli_prepare($link"SELECT Code, Name FROM Country ORDER BY Name LIMIT 5")) {
  •     mysqli_stmt_execute($stmt);
  •     /* bind variables to prepared statement */
  •     mysqli_stmt_bind_result($stmt$col1$col2);
  •     /* fetch values */
  •     while (mysqli_stmt_fetch($stmt)) {
  •         printf("%s %s\n"$col1$col2);
  •     }
  •     /* close statement */
  •     mysqli_stmt_close($stmt);
  • }
  • /* close connection */
  • mysqli_close($link);