本文整理汇总了PHP中DBManager::repairTableParams方法的典型用法代码示例。如果您正苦于以下问题:PHP DBManager::repairTableParams方法的具体用法?PHP DBManager::repairTableParams怎么用?PHP DBManager::repairTableParams使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DBManager
的用法示例。
在下文中一共展示了DBManager::repairTableParams方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: repairTableParams
public function repairTableParams($tablename, $fielddefs, $indices, $execute = true, $engine = null)
{
//Modules with names close to 30 characters may have index names over 30 characters, we need to clean them
foreach ($indices as $key => $value) {
$indices[$key]['name'] = $this->getValidDBName($value['name'], true, 'index');
}
return parent::repairTableParams($tablename, $fielddefs, $indices, $execute, $engine);
}
示例2: testRepairTableParamsAddIndexAndData
public function testRepairTableParamsAddIndexAndData()
{
$tableName = 'test1_' . mt_rand();
$params = array('foo' => array('name' => 'foo', 'type' => 'varchar', 'len' => '255'), 'bar' => array('name' => 'bar', 'type' => 'int'));
$index = array('name' => 'test_index', 'type' => 'index', 'fields' => array('foo', 'bar'));
if ($this->_db->tableExists($tableName)) {
$this->_db->dropTableName($tableName);
}
$this->createTableParams($tableName, $params, array());
$repair = $this->_db->repairTableParams($tableName, $params, array($index), false);
$this->assertRegExp('#MISSING INDEX IN DATABASE.*test_index#i', $repair);
$repair = $this->_db->repairTableParams($tableName, $params, array($index), true);
$idx = $this->_db->get_indices($tableName);
$this->assertArrayHasKey('test_index', $idx);
$this->assertContains('foo', $idx['test_index']['fields']);
$this->assertContains('bar', $idx['test_index']['fields']);
$this->dropTableName($tableName);
}
示例3: repairTableParams
/**
* @see DBManager::repairTableParams()
*
* For MySQL, we can write the ALTER TABLE statement all in one line, which speeds things
* up quite a bit. So here, we'll parse the returned SQL into a single ALTER TABLE command.
*/
public function repairTableParams($tablename, $fielddefs, $indices, $execute = true, $engine = null)
{
$sql = parent::repairTableParams($tablename, $fielddefs, $indices, false, $engine);
if ($sql == '') {
return '';
}
if (stristr($sql, 'create table')) {
return $sql;
}
// first, parse out all the comments
$match = array();
preg_match_all("!/\\*.*?\\*/!is", $sql, $match);
$commentBlocks = $match[0];
$sql = preg_replace("!/\\*.*?\\*/!is", '', $sql);
// now, we should only have alter table statements
// let's replace the 'alter table name' part with a comma
$sql = preg_replace("!alter table {$tablename}!is", ', ', $sql);
// re-add it at the beginning
$sql = substr_replace($sql, '', strpos($sql, ','), 1);
$sql = str_replace(";", "", $sql);
$sql = str_replace("\n", "", $sql);
$sql = "ALTER TABLE {$tablename} {$sql}";
if ($execute) {
$this->query($sql, 'Error with MySQL repair table');
}
// and re-add the comments at the beginning
$sql = implode("\n", $commentBlocks) . "\n" . $sql . "\n";
return $sql;
}