Beispiel #1
0
 public function testAutoExecute()
 {
     $rs = $this->db->AutoExecute('tests', array('col1' => 1, 'col2' => 2, 'col3' => 3));
     $this->assertTrue($rs);
     $rs = $this->db->FetchMode('ASSOC')->GetAll('SELECT * FROM tests');
     $this->assertEquals($rs, array(array('id' => 1, 'col1' => 1, 'col2' => 2, 'col3' => 3)));
     $rs = $this->db->AutoExecute('tests', array('col1' => 7), 'UPDATE', 'id=1');
     $this->assertTrue($rs);
     $rs = $this->db->FetchMode('ASSOC')->GetAll('SELECT * FROM tests');
     $this->assertEquals($rs, array(array('id' => 1, 'col1' => 7, 'col2' => 2, 'col3' => 3)));
     $this->assertEquals($this->db->getnumOfRows(), $this->db->getnumOfRowsAffected());
 }
Beispiel #2
0
$password = getenv('MYSQL_PASS') ?: '';
$host = getenv('MYSQL_HOST') ?: '127.0.0.1';
$port = getenv('MYSQL_PORT') ?: '3306';
$db = new DALMP\Database("utf8://{$user}:{$password}@{$host}:{$port}/dalmp");
/**
 *  load zone files to mysql
 *  mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql
 */
$db->PExecute('SET time_zone=?', '+00:00');
$db->FetchMode('ASSOC');
$sql = 'SELECT Name, Continent FROM Country WHERE Population > ? AND Code LIKE ? LIMIT ?';
$rs = $db->PGetAll($sql, 10000000, '%P%', 2);
print_r($rs);
$rs = $db->Execute('DROP TABLE IF EXISTS `tests`');
$rs = $db->Execute('CREATE TABLE `tests` (id INT(11) unsigned NOT NULL AUTO_INCREMENT, col1 varchar(255), col2 varchar(255), col3 varchar(255), status iNT(1), PRIMARY KEY (id))');
$rs = $db->AutoExecute('tests', array('col1' => 'ai eu', 'col2' => 2, 'status' => 0));
/**
 * status value is 0 or 1 on table
 * NOTICE the use of ===
 */
$sql = 'SELECT status FROM tests WHERE id=?';
$rs = $db->PgetOne($sql, 3);
if ($rs === false) {
    echo "no result" . $timer->isCli(1);
} elseif ($rs == 0) {
    echo "{$rs} = 0" . $timer->isCli(1);
} else {
    echo "{$rs} > 0" . $timer->isCli(1);
}
/**
 * passing an array as an argument