/** * Custom write() function * * @param string $session_id * @param string $session_data * * @return bool|string */ public function write($session_id, $session_data) { $hash = md5(($this->lock_to_user_agent && isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '') . ($this->lock_to_ip && isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '') . $this->security_code); /* @noinspection PhpWrongStringConcatenationInspection */ $query = 'INSERT INTO ' . $this->table_name . "\n (\n session_id,\n hash,\n session_data,\n session_expire\n )\n VALUES\n (\n '" . $this->db->escape($session_id) . "',\n '" . $this->db->escape($hash) . "',\n '" . $this->db->escape($session_data) . "',\n '" . $this->db->escape(time() + $this->session_lifetime) . "'\n )\n ON DUPLICATE KEY UPDATE\n session_data = '" . $this->db->escape($session_data) . "',\n session_expire = '" . $this->db->escape(time() + $this->session_lifetime) . "'\n "; // insert OR update session's data $result = $this->db->query($query); if ($result !== false) { return true; } else { return false; } }
public function testQuery() { // query - true $sql = "INSERT INTO " . $this->tableName . "\n SET\n page_template = ?,\n page_type = ?\n "; $return = $this->db->query($sql, array(1.1, 1)); self::assertEquals(true, $return); // query - true $sql = "INSERT INTO " . $this->tableName . "\n SET\n page_template = ?,\n page_type = ?\n "; $tmpDate = new DateTime(); $tmpId = $this->db->query($sql, array('dateTest', $tmpDate)); self::assertEquals(true, $tmpId); // select - true $result = $this->db->select($this->tableName, "page_id = {$tmpId}"); $tmpPage = $result->fetchObject(); self::assertEquals($tmpDate->format('Y-m-d H:i:s'), $tmpPage->page_type); // select - false $result = new Result(); $tmpPage = $result->fetch(); self::assertEquals(false, $tmpPage); $tmpPage = $result->fetchObject(); self::assertEquals(false, $tmpPage); $tmpPage = $result->fetchArray(); self::assertEquals(false, $tmpPage); // query - false $sql = "INSERT INTO " . $this->tableName . "\n SET\n page_template = ?,\n page_type = ?\n "; $return = $this->db->query($sql, array(true, array('test'))); // array('test') => null self::assertEquals(false, $return); // query - false $sql = "INSERT INTO " . $this->tableName . "\n SET\n page_template_lall = ?,\n page_type = ?\n "; $return = $this->db->query($sql, array('tpl_test_new15', 1)); self::assertEquals(false, $return); // query - false $return = $this->db->query('', array('tpl_test_new15', 1)); self::assertEquals(false, $return); }