Created
March 20, 2018 10:41
-
-
Save ifirmawan/7c38e6d220203a5574737e8989003826 to your computer and use it in GitHub Desktop.
Get values from prepare bind param query with new mysqli connection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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