I am trying to make a simple SELECT query to my database with a MySQLi prepared statement. I have read numerous tutorials and followed them very closely but for some reason it is still not working. Below is the query code:
<?php
$user = 'abc';
$dbconn = new mysqli("localhost", "my_user", "my_password", "my_table");
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
if ($stmt = $dbconn->prepare("SELECT id, pass FROM my_table WHERE user=?")) {
$stmt->bind_param("s",$user);
$stmt->execute();
$stmt->bind_result($db_id,$db_pass);
$stmt->fetch();
$stmt->close();
}
$dbconn->close();
echo $db_id . ' ' . $db_pass;
?>
When I run this is does not say I have a connection error but a server error. I have a decent amount of PHP experience but am completely new to MySQLi prepared statements. Any help would be greatly appreciated; thank you for your time.