mysql; $this->db = new MySQL("mysql:host={$params->host};dbname={$params->database}", $params->user, $params->pass); } elseif (($var = getenv('CI'))) { $this->db = new MySQL('host=127.0.0.1;port=3306;dbname=test', 'root'); } } // -------------------------------------------------------------------------- public function testExists() { $this->assertTrue(in_array('mysql', PDO::getAvailableDrivers())); } // -------------------------------------------------------------------------- public function testConnection() { $this->assertIsA($this->db, 'MySQL'); } // -------------------------------------------------------------------------- public function testCreateTable() { //Attempt to create the table $sql = $this->db->util->create_table('create_test', array( 'id' => 'int(10)', 'key' => 'TEXT', 'val' => 'TEXT', ), array( 'id' => 'PRIMARY KEY' ) ); $this->db->query($sql); //Attempt to create the table $sql = $this->db->util->create_table('create_join', array( 'id' => 'int(10)', 'key' => 'TEXT', 'val' => 'TEXT', ), array( 'id' => 'PRIMARY KEY' ) ); $this->db->query($sql); //Check $dbs = $this->db->get_tables(); $this->assertTrue(in_array('create_test', $dbs)); } // -------------------------------------------------------------------------- public function testTruncate() { //$this->markTestSkipped(); $this->db->truncate('create_test'); $this->db->truncate('create_join'); //$ct_query = $this->db->query('SELECT * FROM create_test'); //$cj_query = $this->db->query('SELECT * FROM create_join'); } // -------------------------------------------------------------------------- public function testPreparedStatements() { $sql = <<db->prepare_query($sql, array(1,"boogers", "Gross")); $res = $statement->execute(); $this->assertTrue($res); } // -------------------------------------------------------------------------- public function testPrepareExecute() { $sql = <<db->prepare_execute($sql, array( 2, "works", 'also?' )); $this->assertInstanceOf('PDOStatement', $res); } // -------------------------------------------------------------------------- public function testCommitTransaction() { $res = $this->db->beginTransaction(); $sql = 'INSERT INTO `create_test` (`id`, `key`, `val`) VALUES (10, 12, 14)'; $this->db->query($sql); $res = $this->db->commit(); $this->assertTrue($res); } // -------------------------------------------------------------------------- public function testRollbackTransaction() { $res = $this->db->beginTransaction(); $sql = 'INSERT INTO `create_test` (`id`, `key`, `val`) VALUES (182, 96, 43)'; $this->db->query($sql); $res = $this->db->rollback(); $this->assertTrue($res); } // -------------------------------------------------------------------------- public function testGetSchemas() { $this->assertNull($this->db->get_schemas()); } // -------------------------------------------------------------------------- public function testGetsProcedures() { $this->assertTrue(is_array($this->db->get_procedures())); } // -------------------------------------------------------------------------- public function testGetTriggers() { $this->assertTrue(is_array($this->db->get_triggers())); } // -------------------------------------------------------------------------- public function testGetSequences() { $this->assertNull($this->db->get_sequences()); } public function testBackup() { $this->assertTrue(is_string($this->db->util->backup_structure())); } }