1

I wonder if I still need question mark if I don't want to specify any row. Because bind_param needs it.

$zr="0";
$stmt=$mysqli->prepare("select * from products_db where not prd_id=?");
$stmt->bind_param("i",$zr);//can I skip this line or what?

I search everywhere but there's no such a thing. Once I tried without ? it errors without reason. I might be typo error, something?

Phil
  • 157,677
  • 23
  • 242
  • 245
Wilf
  • 2,297
  • 5
  • 38
  • 82
  • 2
    FYI, no program ever _"errors without reason"_. If you can't see the errors, it just means your environment is not configured to show them. See [How to get useful error messages in PHP?](https://stackoverflow.com/questions/845021/how-to-get-useful-error-messages-in-php) and [How to get MySQLi error information in different environments](https://stackoverflow.com/questions/22662488/how-to-get-mysqli-error-information-in-different-environments) – Phil Nov 27 '18 at 05:27

1 Answers1

2

If you don't need to bind any parameters, you can use mysqli::query()

$result = $mysqli->query('SELECT * FROM products_db');

This both prepares and executes the SQL provided but offers no way to safely bind parameters.

This is roughly equivalent to...

$stmt = $mysqli->prepare('SELECT * FROM products_db');
$result = $stmt->execute();

which you can also use.

Note there are no positional parameters (ie ?) and therefore, no need to use mysqli_stmt::bind_param().

Phil
  • 157,677
  • 23
  • 242
  • 245