本文整理汇总了PHP中PHPWS_DB::touchDB方法的典型用法代码示例。如果您正苦于以下问题:PHP PHPWS_DB::touchDB方法的具体用法?PHP PHPWS_DB::touchDB怎么用?PHP PHPWS_DB::touchDB使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHPWS_DB
的用法示例。
在下文中一共展示了PHPWS_DB::touchDB方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: import
/**
* Imports a SQL dump into the database.
* This function can not be called statically.
* @returns True if successful, false if not successful and report_errors = false or
* Error object if report_errors = true
*/
public static function import($text, $report_errors = true)
{
PHPWS_DB::touchDB();
// first_import makes sure at least one query was completed
// successfully
$first_import = false;
$sqlArray = PHPWS_Text::sentence($text);
$error = false;
foreach ($sqlArray as $sqlRow) {
if (empty($sqlRow) || preg_match("/^[^\\w\\d\\s\\(\\)]/i", $sqlRow)) {
continue;
}
$sqlCommand[] = $sqlRow;
if (preg_match("/;\$/", $sqlRow)) {
$query = implode(' ', $sqlCommand);
$sqlCommand = array();
if (!DB_ALLOW_TABLE_INDEX && preg_match('/^create index/i', $query)) {
continue;
}
PHPWS_DB::homogenize($query);
$result = PHPWS_DB::query($query);
if (DB::isError($result)) {
if ($report_errors) {
return $result;
} else {
PHPWS_Error::log($result);
$error = true;
}
}
$first_import = true;
}
}
if (!$first_import) {
if ($report_errors) {
return PHPWS_Error::get(PHPWS_DB_IMPORT_FAILED, 'core', 'PHPWS_DB::import');
} else {
PHPWS_Error::log(PHPWS_DB_IMPORT_FAILED, 'core', 'PHPWS_DB::import');
$error = true;
}
}
if ($error) {
return false;
} else {
return true;
}
}
示例2: export
public function export($structure = true, $contents = true)
{
PHPWS_DB::touchDB();
$table = $this->addPrefix($this->tables[0]);
if ($structure == true) {
$GLOBALS['PHPWS_DB']['connection']->loadModule('Reverse', null, true);
$columns = $GLOBALS['PHPWS_DB']['connection']->tableInfo($table);
$column_info = $this->parseColumns($columns);
$index = $this->getIndex();
$sql[] = "CREATE TABLE {$table} ( " . implode(', ', $column_info['parameters']) . ' );';
if (isset($column_info['index'])) {
$sql = array_merge($sql, $column_info['index']);
}
}
if ($contents == true) {
if ($rows = $this->select()) {
if (PHPWS_Error::isError($rows)) {
return $rows;
}
foreach ($rows as $dataRow) {
foreach ($dataRow as $key => $value) {
$allKeys[] = $key;
$allValues[] = PHPWS_DB::escape($value);
}
$sql[] = "INSERT INTO {$table} (" . implode(', ', $allKeys) . ') VALUES (' . implode(', ', $allValues) . ');';
$allKeys = $allValues = array();
}
}
}
if (!empty($sql)) {
return implode("\n", $sql);
} else {
return null;
}
}