Advertisement
AMONRA75

PHP - MYSQLI CONNECT AND QUERY

Jan 22nd, 2019
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.50 KB | None | 0 0
  1.  
  2.  
  3. $db = new mysqli('localhost','user','password','database');
  4. $resource = $db->query('SELECT field FROM table WHERE 1');
  5. $row = $resource->fetch_assoc();
  6. echo "{$row['field']}";
  7. $resource->free();
  8. $db->close();
  9.  
  10.  
  11. If you're grabbing more than one row, I do it like this:
  12.  
  13. $db = new mysqli('localhost','user','password','database');
  14. $resource = $db->query('SELECT field FROM table WHERE 1');
  15. while ( $row = $resource->fetch_assoc() ) {
  16.    echo "{$row['field']}";
  17. }
  18. $resource->free();
  19. $db->close();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement