juliarnasution

Untitled

Feb 22nd, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.14 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. /* Create table doesn't return a resultset */
  11. if (mysqli_query($link, "CREATE TEMPORARY TABLE myCity LIKE City") === TRUE) {
  12.     printf("Table myCity successfully created.\n");
  13. }
  14.  
  15. /* Select queries return a resultset */
  16. if ($result = mysqli_query($link, "SELECT Name FROM City LIMIT 10")) {
  17.     printf("Select returned %d rows.\n", mysqli_num_rows($result));
  18.  
  19.     /* free result set */
  20.     mysqli_free_result($result);
  21. }
  22.  
  23. /* If we have to retrieve large amount of data we use MYSQLI_USE_RESULT */
  24. if ($result = mysqli_query($link, "SELECT * FROM City", MYSQLI_USE_RESULT)) {
  25.  
  26.     /* Note, that we can't execute any functions which interact with the
  27.        server until result set was closed. All calls will return an
  28.        'out of sync' error */
  29.     if (!mysqli_query($link, "SET @a:='this will not work'")) {
  30.         printf("Error: %s\n", mysqli_error($link));
  31.     }
  32.     mysqli_free_result($result);
  33. }
  34.  
  35. mysqli_close($link);
  36. ?>
Add Comment
Please, Sign In to add comment