예제 #1
0
 /**
  * 执行sql
  */
 private function _execute($command = '')
 {
     $exeSql = empty($command) ? trim($this->_gets->getParam('command')) : $command;
     $formatExeSql = XUtils::splitsql($exeSql);
     foreach ($formatExeSql as $sql) {
         if (empty($sql)) {
             continue;
         }
         try {
             $resultData = self::_executeCommand($sql);
             if (false !== $resultData['result']) {
                 if ($resultData['type'] == 'query') {
                     if (empty($resultData['result'])) {
                         echo '执行完成';
                     }
                     $fields = array_keys($resultData['result'][0]);
                     echo $this->render('query_result', array('fields' => $fields, 'dataList' => $resultData['result'], 'command' => $command), true);
                 } else {
                     echo "<div style='color:red;padding:10px 0'>执行完成: {$sql}</div>";
                 }
             } else {
                 echo "执行失败";
             }
         } catch (Exception $e) {
             echo "<div style='color:red;padding:10px 0'>执行失败: {$sql}</div>";
         }
     }
 }