本文整理汇总了PHP中Kwf_Model_Abstract::export方法的典型用法代码示例。如果您正苦于以下问题:PHP Kwf_Model_Abstract::export方法的具体用法?PHP Kwf_Model_Abstract::export怎么用?PHP Kwf_Model_Abstract::export使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Kwf_Model_Abstract
的用法示例。
在下文中一共展示了Kwf_Model_Abstract::export方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: export
public function export($format, $select = array(), $options = array())
{
if ($format == self::FORMAT_SQL) {
$wherePart = '';
if ($select) {
if (!is_object($select)) {
if (is_string($select)) {
$select = array($select);
}
$select = $this->select($select);
}
$dbSelect = $this->_getDbSelect($select);
$whereParts = $dbSelect->getPart(Zend_Db_Select::WHERE);
$wherePart = implode(' ', $whereParts);
// check if a row is exported and quit, if none
$dbSelect->limit(1);
$hasRows = $dbSelect->query()->fetchAll();
if (!count($hasRows)) {
return '';
}
}
if ($wherePart) {
$wherePart = '--where="' . $wherePart . '" ';
}
$systemData = $this->_getSystemData();
$filename = tempnam('/tmp', 'modelimport');
$cmd = "{$systemData['mysqlDir']}mysqldump --add-drop-table=false ";
$cmd .= "--skip-add-locks --complete-insert ";
$cmd .= "--no-create-info=true " . $wherePart . "{$systemData['mysqlOptions']} {$systemData['tableName']} | gzip -c > {$filename}";
exec($cmd, $output, $ret);
if ($ret != 0) {
throw new Kwf_Exception("SQL export failed");
}
$ret = file_get_contents($filename);
unlink($filename);
return $ret;
} else {
if ($format == self::FORMAT_CSV) {
if (!is_object($select)) {
if (is_string($select)) {
$select = array($select);
}
$select = $this->select($select);
}
$tmpExportFolder = realpath('temp') . '/modelcsvex' . uniqid();
$filename = $tmpExportFolder . '/csvexport';
$dbSelect = $this->_createDbSelectWithColumns($select, $options);
$sqlString = $dbSelect->assembleIntoOutfile($filename);
$dbSelect->limit(1);
$fieldResult = $dbSelect->query()->fetchAll();
$columnsCsv = '';
if (count($fieldResult)) {
mkdir($tmpExportFolder, 0777);
$columns = array_keys($fieldResult[0]);
$columnsCsv = '"' . implode('","', $columns) . '"';
$this->executeSql($sqlString);
$cmd = "{ echo '{$columnsCsv}'; cat {$filename}; } | gzip -c > {$filename}.gz";
exec($cmd, $output, $ret);
if ($ret != 0) {
throw new Kwf_Exception("CSV-SQL export failed");
}
if (!file_exists($filename . '.gz')) {
throw new Kwf_Exception("Error exporting csv from model - target file has not been created");
}
unlink($filename);
$ret = file_get_contents($filename . '.gz');
unlink($filename . '.gz');
rmdir($tmpExportFolder);
return $ret;
} else {
return '';
}
} else {
if ($format == self::FORMAT_ARRAY) {
if (!is_object($select)) {
if (is_string($select)) {
$select = array($select);
}
$select = $this->select($select);
}
if ($select->hasPart(Kwf_Model_Select::UNION)) {
$select = clone $select;
$unions = $select->getPart(Kwf_Model_Select::UNION);
$select->unsetPart(Kwf_Model_Select::UNION);
$selects = array($select);
$selects = array_merge($selects, $unions);
$ret = array();
while ($selects) {
//split up into blocks of 150, mysql doesn't take more
$curSelects = array_splice($selects, 0, min(150, count($selects)));
$unions = array();
foreach ($curSelects as $s) {
$unions[] = $this->_createDbSelectWithColumns($s, $options);
}
$ret = array_merge($ret, $this->getAdapter()->query(implode(" UNION ", $unions))->fetchAll());
}
return $ret;
} else {
$dbSelect = $this->_createDbSelectWithColumns($select, $options);
if (!$dbSelect) {
//.........这里部分代码省略.........