本文整理汇总了PHP中ezcDbSchema::writeToDb方法的典型用法代码示例。如果您正苦于以下问题:PHP ezcDbSchema::writeToDb方法的具体用法?PHP ezcDbSchema::writeToDb怎么用?PHP ezcDbSchema::writeToDb使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ezcDbSchema
的用法示例。
在下文中一共展示了ezcDbSchema::writeToDb方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
public function setUp()
{
try {
$this->db = ezcDbInstance::get();
if ($this->db === false) {
$this->markTestSkipped("You must provide a database to runtests.php.");
}
$tables = array(self::$table => new ezcDbSchemaTable(array(self::$fieldId => new ezcDbSchemaField('integer', false, true, null, true), self::$fieldUser => new ezcDbSchemaField('text', 32, true), self::$fieldPassword => new ezcDbSchemaField('text', 64, true), self::$fieldName => new ezcDbSchemaField('text', 64, true), self::$fieldCountry => new ezcDbSchemaField('text', 32, true)), array(self::$fieldUser => new ezcDbSchemaIndex(array(self::$fieldUser => new ezcDbSchemaIndexField()), false, false))));
$schema = new ezcDbSchema($tables);
$schema->writeToDb($this->db);
} catch (Exception $e) {
// Oracle seems to skip every other test if the next line is enabled
// $this->markTestSkipped( "Cannot create test table '" . self::$table . "'. " . $e->getMessage() );
}
if (!isset($this->db)) {
$this->markTestSkipped("You must provide a database to runtests.php. Run runtests.php --help to see how to specify a database.");
}
try {
$query = new ezcQueryInsert($this->db);
$query->insertInto($this->db->quoteIdentifier(self::$table))->set($this->db->quoteIdentifier(self::$fieldId), $query->bindValue('1'))->set($this->db->quoteIdentifier(self::$fieldUser), $query->bindValue('jan.modaal'))->set($this->db->quoteIdentifier(self::$fieldPassword), $query->bindValue(sha1('qwerty')))->set($this->db->quoteIdentifier(self::$fieldName), $query->bindValue('Jan Modaal'))->set($this->db->quoteIdentifier(self::$fieldCountry), $query->bindValue('NL'));
$stmt = $query->prepare();
$stmt->execute();
$query = new ezcQueryInsert($this->db);
$query->insertInto($this->db->quoteIdentifier(self::$table))->set($this->db->quoteIdentifier(self::$fieldId), $query->bindValue('2'))->set($this->db->quoteIdentifier(self::$fieldUser), $query->bindValue('john.doe'))->set($this->db->quoteIdentifier(self::$fieldPassword), $query->bindValue(crypt('foobar', 'jo')))->set($this->db->quoteIdentifier(self::$fieldName), $query->bindValue('John Doe'))->set($this->db->quoteIdentifier(self::$fieldCountry), $query->bindValue('US'));
$stmt = $query->prepare();
$stmt->execute();
$query = new ezcQueryInsert($this->db);
$query->insertInto($this->db->quoteIdentifier(self::$table))->set($this->db->quoteIdentifier(self::$fieldId), $query->bindValue('3'))->set($this->db->quoteIdentifier(self::$fieldUser), $query->bindValue('zhang.san'))->set($this->db->quoteIdentifier(self::$fieldPassword), $query->bindValue(md5('asdfgh')))->set($this->db->quoteIdentifier(self::$fieldName), $query->bindValue('Zhang San'))->set($this->db->quoteIdentifier(self::$fieldCountry), $query->bindValue('CN'));
$stmt = $query->prepare();
$stmt->execute();
$query = new ezcQueryInsert($this->db);
$query->insertInto($this->db->quoteIdentifier(self::$table))->set($this->db->quoteIdentifier(self::$fieldId), $query->bindValue('4'))->set($this->db->quoteIdentifier(self::$fieldUser), $query->bindValue('hans.mustermann'))->set($this->db->quoteIdentifier(self::$fieldPassword), $query->bindValue('abcdef'))->set($this->db->quoteIdentifier(self::$fieldName), $query->bindValue('Hans Mustermann'))->set($this->db->quoteIdentifier(self::$fieldCountry), $query->bindValue('DE'));
$stmt = $query->prepare();
$stmt->execute();
} catch (Exception $e) {
$this->markTestSkipped("Cannot insert test values into table '" . self::$table . "'. " . $e->getMessage());
}
}
示例2: testAddingAutoIncrementField
public function testAddingAutoIncrementField()
{
$dbh = $this->db;
$schema1 = new ezcDbSchema(array('table10801' => new ezcDbSchemaTable(array('id' => ezcDbSchemaField::__set_state(array('type' => 'integer', 'length' => false, 'notNull' => false, 'default' => 0, 'autoIncrement' => false, 'unsigned' => false)), 'text' => new ezcDbSchemaField('text')))));
$schema2 = new ezcDbSchema(array('table10801' => new ezcDbSchemaTable(array('id' => ezcDbSchemaField::__set_state(array('type' => 'integer', 'length' => false, 'notNull' => true, 'default' => null, 'autoIncrement' => true, 'unsigned' => false)), 'text' => new ezcDbSchemaField('text')))));
$schema1->writeToDb($dbh);
$diff = ezcDbSchemaComparator::compareSchemas($schema1, $schema2);
$diff->applyToDb($dbh);
$q = $dbh->createInsertQuery();
$stmt = $q->insertInto($dbh->quoteIdentifier('table10801'))->set($dbh->quoteIdentifier('text'), $q->bindValue('text'))->prepare();
$stmt->execute();
$q = $dbh->createSelectQuery();
$stmt = $q->select('*')->from($dbh->quoteIdentifier('table10801'))->prepare();
$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
$this->assertEquals(1, $result[0]['id']);
}
示例3: testWriteWithUnsupportedType
public function testWriteWithUnsupportedType()
{
$tables = array('prefix_bugdb_comments' => new ezcDbSchemaTable(array('email' => new ezcDbSchemaField('slartibartfast', 32)), array()));
$schema = new ezcDbSchema($tables);
try {
$schema->writeToDb($this->db);
self::fail("Expected exception is not thrown.");
} catch (ezcDbSchemaUnsupportedTypeException $e) {
self::assertRegexp("@The field type 'slartibartfast' is not supported with the '(.*)' handler.@", $e->getMessage());
}
}