/ Published in: PHP
Expand |
Embed | Plain Text
$mysql = new mysqli('localhost', 'root', 'root', 'databaseName') or die('There was a problem connecting to the database'); $stmt = $mysql->prepare('SELECT id, title, content FROM tableName'); $stmt->execute(); $stmt->bind_result($id, $title, $content); while($row = $stmt->fetch()) : ?> <?php endwhile; ?>
Comments
Subscribe to comments
You need to login to post a comment.

1) Create mysqli connection, and pass the host, username, password, and desired database. 2) Prepare your SQL query. Replace mine with whatever you need to select. 3) Execute the statement 4) Bind the results to variables. Make sure that you pass the same number of arguments to bind_result as you selected in your SQL query -- in this case, three. 7) Cycle through the rows, and echo out the title and content.
Cool, and what if we need parameters in the statement? Can you give an example or a link to one? Thanks.
@aelien - Sure, you use ? and then bind the parameters, accordingly. I'm heading out for the evening, but I'll add a new snippet tomorrow.
@Nettuts - Could you past the snippet with parameters pls?