/**
  * Public utility to log a src_activity without using doctrine.
  *
  * @param int     $usrid
  * @param array   $srcids
  * @param string  $dtim
  * @param string  $desc
  * @param string  $note
  */
 public static function log_raw($usrid, $srcids, $dtim, $desc, $note)
 {
     // collect default values
     if (!$dtim) {
         $dtim = air2_date();
     }
     if (!$desc) {
         $desc = '';
     }
     if (!$note) {
         $note = '';
     }
     // create generic mapping
     $mapping = array('src_activity' => array('sact_src_id' => array('map' => 0), 'sact_actm_id' => array('val' => 40), 'sact_dtim' => array('val' => $dtim), 'sact_desc' => array('val' => $desc), 'sact_notes' => array('val' => $note), 'sact_cre_user' => array('val' => $usrid), 'sact_upd_user' => array('val' => $usrid), 'sact_cre_dtim' => array('val' => $dtim), 'sact_upd_dtim' => array('val' => $dtim)));
     // import data (FAST if there are alot of rows)
     $rdr = new ArrayReader($srcids);
     $conn = AIR2_DBManager::get_master_connection();
     if (count($srcids) < 10) {
         $wrt = new SqlWriter($conn, $mapping);
         $wrt->write_data($rdr);
     } else {
         $wrt = new MySqlImporter('/tmp', $mapping, $conn);
         $wrt->write_data($rdr);
         $wrt->exec_load_infile();
     }
     // check for errors
     $errs = $wrt->get_errors();
     if (count($errs) > 0) {
         $str = implode(', ', $errs);
         throw new Exception("Errors on activity logging: {$str}");
     }
 }
Esempio n. 2
0
$db_cfg['database'] = $cg_data["database"];
*/
$db_cfg['hostspec'] = 'localhost';
$db_cfg['port'] = '3306';
$db_cfg['username'] = '******';
$db_cfg['password'] = '******';
$db_cfg['database'] = 'DEV_tpm_watt';
$db_cfg['charset'] = 'utf8';
$db = Pft_Db::getDb($db_cfg);
$default_tables = "";
//------------------------------
$cmd = @$_REQUEST['cmd'];
if ('backup' == $cmd) {
    $tables = @$_REQUEST['tables'];
    $tableArr = explode("\n", $tables);
    $theWriter = new SqlWriter();
    foreach ($tableArr as $table) {
        $table = trim($table);
        if (!$table) {
            continue;
        }
        //Drop
        $theWriter->writeln("\nDROP TABLE IF EXISTS {$table};");
        //Create New
        $row = $db->getRow("show create table {$table};");
        $createSql = $row["Create Table"];
        $theWriter->writeln($createSql . ";\n");
        //Insert Data
        $rs = $db->getResult("select * from {$table};");
        while ($row = $rs->fetchRow()) {
            $values = array();