I'm converting a query to prepared statements for the first time and I'm having trouble figuring out how to extract the data...
Here's my code:
/* Create a new mysqli object with database connection parameters */
$mysqli = new mysqli($hostname_db, $username_db, $password_db, $database_db);
if(mysqli_connect_errno()) {
echo "Connection Failed: " . mysqli_connect_errno();
exit();
}
if($stmt = $mysqli -> prepare("SELECT name FROM table WHERE id=?")) {
/* Bind parameters, s - string, b - blob, i - int, etc */
$stmt -> bind_param("i", $rid);
$stmt -> execute();
$stmt -> bind_result($result);
$stmt -> fetch();
$stmt -> close();
}
$mysqli -> close();
In this example, I was able to display the results in the body of the page like this:
<?php echo $results; ?>
However, when I changed the query in the example above to grab all the fields, I couldn't figure out how to display it:
SELECT * FROM table WHERE id = ?
This did not work:
<?php echo $results['id'] ?>
What am I missing here? How would I display a random field name from that query?
THanks!!