0

I don't get the bind param in php. Why must use bind but not just execute the query directly? is it because the query format is an array?

enter image description here

Voice
  • 194
  • 6
user3207200
  • 33
  • 1
  • 3

1 Answers1

0

Assuming by the bind_param() function you're using mysqli extension. There is no clear answer to "Why can't you just execute the query itself?" except this one.

You're not using a simple query in this case, but you are creating a prepared statement. Prepared statements as Wikipedia states are parameterized form of queries.

So you can't execute a query which is missing parameters, in this case you're probably executing this query :

INSERT INTO people (first_name, last_name, bio, created) VALUES (?, ?, ?, YOUR_TIME_FUNCTION)

As you can notice three parameters are missing, so you can't possibly execute that query in that state. Instead, if you have a static query you can use the mysqli_query() function, which won't accept parameters since it expects an executable query.

Kei
  • 771
  • 6
  • 17