Jump to content

Do prepared statements expire?


NotionCommotion

Recommended Posts

For instance, if used in the following fictional script, they might be created and remain active for months at a time.  Is there any  concern about memory never being released, or anything other to watch out for?  Is this approach okay, or is one better creating the prepared statement, doing the work, and then closing it typical for most http request?

 

Thanks

$stmtSelect=$this->pdo->prepare('SELECT a, b, c FROM table_1 WHERE d=?');
$stmtInsert=$this->pdo->prepare('INSERT INTO table_1(a, b, c, d) VALUES(?,?,?,?)');
$stmtUpdate=$this->pdo->prepare('UPDATE table_1 SET a=?, b=?, c=? WHERE d=?');

$socket->on('connection', function (ConnectionInterface $conn) use($stmtSelect, $stmtInsert, $stmtUpdate) {
    $conn->on('data', function ($data) use ($conn) use($stmtSelect, $stmtInsert, $stmtUpdate) {
       $d=doSomething($data);
       if(someCondition) {
          $stmtSelect->execute([$d->a,$d->b,$d->c,$d->d]);
       }
       elseif(someOtherCondition{
           $stmtInsert->execute([$d->a,$d->b,$d->c,$d->d]);
       }
       else {
           $stmtUpdate->execute([$d->a,$d->b,$d->c,$d->d]);
       }
   });
});


//Script never gets here and it runs forever...

 

Link to comment
Share on other sites

If you're using it often then the "isn't being used" bit is not true.

 

Like tables at a restaurant, it's just not a Nice Thing To Do to reserve resources if you're not going to use them. Even if it's one small table at a large restaurant.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.