mkaplan

Sample mysqli with PHP

Jun 5th, 2011
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.66 KB | None | 0 0
  1. $link = mysqli_connect(
  2.             'localhost',  /* The host to connect to */
  3.             'root',       /* The user to connect as */
  4.             '',   /* The password to use */
  5.             'test');     /* The default database to query */
  6.  
  7.     if (!$link) {
  8.         printf("Can't connect to MySQL Server. Errorcode: %s\n", mysqli_connect_error());
  9.         exit;
  10.     }
  11.  
  12.  
  13.     $stmt=$link->prepare("SELECT column FROM `tablename`);
  14.  
  15.     if (!$stmt->execute()){
  16.         echo "Error executing prepared statement<br />";
  17.         die();
  18.     }
  19.  
  20.     $stmt->bind_result($selectResult);
  21.  
  22.     while($stmt->fetch())
  23.         echo $selectResult.'<br/>';
  24.            
  25.     $stmt->close();
  26.     $link->close();
Advertisement
Add Comment
Please, Sign In to add comment