Esempio n. 1
0
 public function test_put()
 {
     $this->cache->put(2, null, "putting a non mysqli_stmt should fail");
     $this->assertFalse($this->cache->exists(2));
     $this->cache->put(2, $this->cache->get(0));
     $this->assertTrue($this->cache->exists(2), "putting a mysql_stmt should work");
 }
Esempio n. 2
0
 /**
  * @param $sql
  *
  * @return \mysqli_stmt
  * @throws \Exception
  */
 public function get_statement_from_sql($sql) : \mysqli_stmt
 {
     $key = md5($sql);
     if (!$this->statementCache->exists($key)) {
         // prepare the statement
         $statement = $this->mysqli->prepare($sql);
         if ($statement === false) {
             throw new \Exception("statment preparation failed: ({$this->mysqli->errno}) {$this->mysqli->error}" . PHP_EOL . $sql);
         }
         $this->statementCache->put($key, $statement);
     }
     return $this->statementCache->get($key);
 }