Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. <?php
  2. $link = mysqli_connect("localhost", "my_user", "my_password", "world");
  3.  
  4. /* check connection */
  5. if (mysqli_connect_errno()) {
  6. printf("Connect failed: %s\n", mysqli_connect_error());
  7. exit();
  8. }
  9.  
  10. $city = "Amersfoort";
  11.  
  12. /* create a prepared statement */
  13. if ($stmt = mysqli_prepare($link, "SELECT District FROM City WHERE Name=?")) {
  14.  
  15. /* bind parameters for markers */
  16. mysqli_stmt_bind_param($stmt, "s", $city);
  17.  
  18. /* execute query */
  19. mysqli_stmt_execute($stmt);
  20.  
  21. /* bind result variables */
  22. mysqli_stmt_bind_result($stmt, $district);
  23.  
  24. /* fetch value */
  25. mysqli_stmt_fetch($stmt);
  26.  
  27. printf("%s is in district %s\n", $city, $district);
  28.  
  29. /* close statement */
  30. mysqli_stmt_close($stmt);
  31. }
  32.  
  33. /* close connection */
  34. mysqli_close($link);
  35. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement