function execute($sql)
 {
     if (!$this->write_connection()) {
         throw new Exception("Write connection not established");
         return false;
     }
     //echo "<br> " . $sql . "<br>";
     $start = microtime(true);
     $result = $this->write->query($sql);
     $end = microtime(true);
     $database_name = $this->write_settings['server'] . " (" . $this->write_settings["host"];
     if (isset($this->write_settings["port"])) {
         $database_name .= ":" . $this->write_settings["port"];
     }
     $database_name .= ")";
     if (!$result && $this->write->errno == 1205) {
         error_log("Database::execute() failed with error 1205, retrying in 3 seconds.");
         sleep(3);
         $this->result = $this->write->query($sql);
     }
     Debugger::query($sql, $end - $start, $database_name);
     if (!$result) {
         $error = new MySqliError($this->write->errno, $this->write->error, $sql);
         if (count($this->errors) > self::$MAX_ERRORS) {
             array_shift($this->errors);
         }
         $this->errors[] = $error;
         return false;
     }
     return $result;
 }
 function write($keyspace, $key, $column_family, $data, $consistency)
 {
     try {
         Loader::load("vendor", "phpcassa/columnfamily.php");
         $columnFamily = new columnFamily($this->connection($keyspace), $column_family);
         //echo "use phpcassa!\n";
         //exit;
         if (Config::isLive() || Config::isStaging()) {
             return $columnFamily->insert($key, $data, null, null, $consistency);
         }
         $time = $this->microsecond_timestamp();
         $cassandra_mutations = array();
         foreach ($data as $key => $value) {
             $cassandra_mutations[$key][$column_family][] = new cassandra_Mutation(array("column_or_supercolumn" => new cassandra_ColumnOrSuperColumn(array("column" => new cassandra_Column(array("name" => $key, "value" => $value, "timestamp" => $time))))));
         }
         //Debugger::log("set keyspace $keyspace");
         $this->set_keyspace($keyspace);
         $start = microtime(true);
         $this->get_client()->batch_mutate($cassandra_mutations, $this->consistency());
         $end = microtime(true);
         if (json_encode($cassandra_mutations) == null) {
             print_r($cassandra_mutations);
             exit;
         }
         //error_log("Thrift::batch_mutate(".json_encode($cassandra_mutations).") " . "(".$this->host .":".$this->settings["port"].")");
         Debugger::query("Thrift::batch_mutate(" . json_encode($cassandra_mutations) . ")", $end - $start, $keyspace . "(" . $this->settings["ip"] . ":" . $this->settings["port"] . ")");
         return true;
     } catch (Exception $e) {
         $info = isset($e->why) ? $e->why : get_class($e);
         throw new Exception("Database connection is not available: {$info} {$this->host}");
         return false;
     }
 }
 static function set($key, $value, $ttl = 0)
 {
     if (self::isAvailable()) {
         $start = microtime();
         $start = explode(" ", $start);
         $start = $start[1] + $start[0];
         self::getInstance()->cache->set($key, $value, 0, $ttl);
         $end = microtime();
         $end = explode(" ", $end);
         $end = $end[1] + $end[0];
         $database_name = "MEMCACHE";
         Debugger::query("***MemCache SET: {$key}***", $end - $start, __CLASS__);
     } else {
         error_log("MEMCACHE IS UNAVAILABLE. PLEASE CALL MemCache::isAvailable() before using!!!!");
     }
 }