I have two questions regarding codes below.
- I know the second code is correct but not sure if first is also correct both do same thing first one is just easy to write.
- I want to count the number of rows in database for the selected element
if ($query->num_rows == 1) {
doesn't work so how torowcount
for the code below.
First code:
$query = $db->prepare("SELECT * from users WHERE username = :username");
$query->execute(array(':username'=>$un));
Second:
$result = "SELECT * from users WHERE username = :username";
$query = $db->prepare( $result );
$stmt->bindValue(':username'=>$un);
$query->execute($stmt);