Skip to content

Instantly share code, notes, and snippets.

@ifirmawan
Created March 20, 2018 10:41
Show Gist options
  • Save ifirmawan/7c38e6d220203a5574737e8989003826 to your computer and use it in GitHub Desktop.
Save ifirmawan/7c38e6d220203a5574737e8989003826 to your computer and use it in GitHub Desktop.
Get values from prepare bind param query with new mysqli connection
<?php
$servername = "localhost";
$username = "root";
$password = "secret";
$dbname = "myDB";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$email = 'admin@admin.com';
$password = sha1('password');
$query = $conn->prepare('SELECT id,username,email FROM users WHERE email = ? AND password = ?');
$query->bind_param('ss',$email,$password);
$query->execute();
$query->bind_result($id,$username,$email); // create new variable with the same of columns in table
while ($query->fetch()) {
var_dump($id); // show data in column id
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment