Prepared Statements: Read


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. $mysql = new mysqli('localhost', 'root', 'root', 'databaseName') or die('There was a problem connecting to the database');
  2. $stmt = $mysql->prepare('SELECT id, title, content FROM tableName');
  3. $stmt->execute();
  4. $stmt->bind_result($id, $title, $content);
  5.  
  6.  
  7. while($row = $stmt->fetch()) : ?>
  8.  
  9. <h2> <?php echo $title; ?> </h2>
  10. <p> <?php echo $content; ?> </p>
  11.  
  12. <?php endwhile; ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.