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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.