当前位置: 首页>>代码示例>>PHP>>正文


PHP OA_Dal::batchInsertPath方法代码示例

本文整理汇总了PHP中OA_Dal::batchInsertPath方法的典型用法代码示例。如果您正苦于以下问题:PHP OA_Dal::batchInsertPath方法的具体用法?PHP OA_Dal::batchInsertPath怎么用?PHP OA_Dal::batchInsertPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在OA_Dal的用法示例。


在下文中一共展示了OA_Dal::batchInsertPath方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: _batchInsertMySQL

 private function _batchInsertMySQL($qTableName, $fieldList, $aValues, $replace)
 {
     $oDbh = OA_DB::singleton();
     // File path defaults to var/cache
     if (!isset(self::$batchInsertPath)) {
         self::$batchInsertPath = MAX_PATH . '/var/cache';
     }
     // Create file path using hostname and table name
     $filePath = self::$batchInsertPath . '/' . OX_getHostName() . '-batch-' . $qTableName . '.csv';
     if (DIRECTORY_SEPARATOR == '\\') {
         // On windows, MySQL expects slashes as directory separators
         $filePath = str_replace('\\', '/', $filePath);
     }
     if ($replace) {
         $replace = ' REPLACE ';
     } else {
         $replace = '';
     }
     // Set up CSV delimiters, quotes, etc
     $delim = "\t";
     $quote = '"';
     $eol = "\n";
     $null = 'NULL';
     // Disable error handler
     RV::disableErrorHandling();
     $fp = fopen($filePath, 'wb');
     if (!$fp) {
         return MAX::raiseError('Error creating the tmp file ' . $filePath . ' containing the batch INSERTs.', PEAR_ERROR_RETURN);
     }
     // ensure that when maintenance is run in crontab, as root eg.
     // the file can still be overwritten by maintenance ran from the UI
     @chmod($filePath, 0777);
     foreach ($aValues as $aRow) {
         // Stringify row
         $row = '';
         foreach ($aRow as $value) {
             if (!isset($value) || is_null($value) || $value === false) {
                 $row .= $null . $delim;
             } else {
                 $row .= $quote . $value . $quote . $delim;
             }
         }
         // Replace delim with eol
         $row[strlen($row) - 1] = $eol;
         // Append
         $ret = fwrite($fp, $row);
         if (!$ret) {
             fclose($fp);
             unlink($filePath);
             return MAX::raiseError('Error writing to the tmp file ' . $filePath . ' containing the batch INSERTs.', PEAR_ERROR_RETURN);
         }
     }
     fclose($fp);
     $query = "\n            LOAD DATA LOCAL INFILE\n                '{$filePath}'\n                {$replace}\n            INTO TABLE\n                {$qTableName}\n            FIELDS TERMINATED BY\n                " . $oDbh->quote($delim) . "\n            ENCLOSED BY\n                " . $oDbh->quote($quote) . "\n            ESCAPED BY\n                ''\n            LINES TERMINATED BY\n                " . $oDbh->quote($eol) . "\n        \t{$fieldList}\n        ";
     $result = $oDbh->exec($query);
     @unlink($filePath);
     // Enable error handler again
     RV::enableErrorHandling();
     return $result;
 }
开发者ID:akirsch,项目名称:revive-adserver,代码行数:60,代码来源:Dal.php


注:本文中的OA_Dal::batchInsertPath方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。