0

Here, $user_id is single quoted:

$select = $conn->query("SELECT firstname,lastname FROM users WHERE user_id = '$user_id'");
$row = $select->fetch_assoc();
    print_r($row);

Here, $user_id is not single quoted

$select = $conn->query("SELECT firstname,lastname FROM users WHERE user_id = $user_id");
$row = $select->fetch_assoc();
    print_r($row);

If $user_id = 1, does '1' == 1?? Both return associative array of $user_id = 1.

cyberbit
  • 1,345
  • 15
  • 22
pnr2711
  • 1
  • 2

1 Answers1

0

For your use case, yes, '1' == 1.

From the docs:

To cast a string to a numeric value in numeric context, you normally do not have to do anything other than to use the string value as though it were a number:

mysql> SELECT 1+'1';
       -> 2
cyberbit
  • 1,345
  • 15
  • 22