php - Do I need to persist a prepared statement? -


i have following code:

public function getdefinitions($wordid) {     $query = $this->dbc->prepare('select * definitions wordid = ?');      $query->bind_param('i', $wordid);     $query->execute();      // ...      $query->close();      return $result; } 

it seem recreate prepared statement each invocation. not seem take advantage of full benefit of prepared statements. in case these prepare statements stored server side. true?

if so, should store prepare statement (in case property) persist between invocations. there way persist prepared statement between requests? assume that's stored procedure?

currently using mysqli. please note api difference if using driver (e.g. pdo).

should store prepare statement (in case property) persist between invocations.

i wouldn't "should". may, if foresee lot of consequent invocations (which cannot group call @ once). either way, scarcely able notice real life difference.

is there way persist prepared statement between requests?

in php - no. prepared statements connection-based, connection closed along request, , persistent connections won't either, mysqli using designated mechanism clean connection state before reuse.

please note api difference if using driver (e.g. pdo).

pdo has advantage on mysqli can emulate prepared statements, eliminating such negligible overhead of 2 database calls, makes more suitable real life usage (beside other key benefits).

in nutshell, "prepare once-multiple execute" feature of native prepared statements can have noticeable effect huge number of queries, starting thousands.


Comments

Popular posts from this blog

php - render data via PDO::FETCH_FUNC vs loop -

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

The canvas has been tainted by cross-origin data in chrome only -