Ejemplo n.º 1
0
 /**
  * @param $sql string
  * @return true|false|resource
  *
  * For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, mysql_query() returns a resource on success, or FALSE on error.
  * For other type of SQL statements, INSERT, UPDATE, DELETE, DROP, etc, mysql_query() returns TRUE on success or FALSE on error.
  */
 protected function doQuery($sql)
 {
     $this->installErrorHandler();
     if ($this->bufferResults()) {
         $ret = mysql_query($sql, $this->mConn);
     } else {
         $ret = mysql_unbuffered_query($sql, $this->mConn);
     }
     $phpError = $this->restoreErrorHandler();
     if ($ret === false) {
         global $wgDBname;
         $error = $this->lastError();
         if (!$error) {
             $error = $phpError;
         }
         $err_num = $this->lastErrno();
         error_log(sprintf("SQL (%s): %d: %s", $wgDBname, $err_num, $error));
         error_log("SQL: invalid query: {$sql}");
         # Wikia change - begin
         switch ($err_num) {
             case 1213:
                 /* deadlock*/
                 error_log("MOLI: deadlock: {$error} ");
                 Wikia::debugBacktrace("MOLI: Deadlock:");
                 break;
             case 2006:
                 /* server has gone away */
                 error_log("MOLI: gone away: {$error} ");
                 Wikia::debugBacktrace("MOLI: gone away:");
                 break;
         }
         # Wikia change - end
     }
     return $ret;
 }
Ejemplo n.º 2
0
 function sl_db()
 {
     if (!@mysql_select_db($this->db, $this->link)) {
         err('数据库' . $this->db . '不存在', "javascript:history.go(-1);");
     }
     @mysql_unbuffered_query("set names {$this->db_charset}");
 }
Ejemplo n.º 3
0
 /**
  * @param $sql string
  * @return resource
  */
 protected function doQuery($sql)
 {
     $this->installErrorHandler();
     if ($this->bufferResults()) {
         $ret = mysql_query($sql, $this->mConn);
     } else {
         $ret = mysql_unbuffered_query($sql, $this->mConn);
     }
     $phpError = $this->restoreErrorHandler();
     if ($ret === false) {
         global $wgDBname;
         $error = $this->lastError();
         if (!$error) {
             $error = $phpError;
         }
         $err_num = $this->lastErrno();
         error_log(sprintf("SQL (%s): %d: %s", $wgDBname, $err_num, $error));
         error_log("SQL: invalid query: {$sql}");
         if ($err_num == 1213) {
             /* deadlock*/
             error_log("MOLI: deadlock: {$error} ");
             Wikia::debugBacktrace("MOLI: Deadlock:");
         }
     }
     return $ret;
 }
Ejemplo n.º 4
0
 function query($sql, $unbuffered = false)
 {
     if (defined('PUN_SHOW_QUERIES')) {
         $q_start = get_microtime();
     }
     if ($unbuffered) {
         $this->query_result = @mysql_unbuffered_query($sql, $this->link_id);
     } else {
         $this->query_result = @mysql_query($sql, $this->link_id);
     }
     if ($this->query_result) {
         if (defined('PUN_SHOW_QUERIES')) {
             $this->saved_queries[] = array($sql, sprintf('%.5f', get_microtime() - $q_start));
         }
         ++$this->num_queries;
         return $this->query_result;
     } else {
         if (defined('PUN_SHOW_QUERIES')) {
             $this->saved_queries[] = array($sql, 0);
         }
         $this->error_no = @mysql_errno($this->link_id);
         $this->error_msg = @mysql_error($this->link_id);
         return false;
     }
 }
Ejemplo n.º 5
0
 /**
  * Standard modular run function.
  *
  * @return tempcode	Results
  */
 function run()
 {
     $out = new ocp_tempcode();
     $tables = $GLOBALS['SITE_DB']->query_select('db_meta', array('DISTINCT m_table'));
     if (count($GLOBALS['SITE_DB']->connection_write) > 4) {
         $GLOBALS['SITE_DB']->connection_write = call_user_func_array(array($GLOBALS['SITE_DB']->static_ob, 'db_get_connection'), $GLOBALS['SITE_DB']->connection_write);
         _general_db_init();
     }
     list($db, $db_name) = $GLOBALS['SITE_DB']->connection_write;
     mysql_select_db($db_name, $db);
     foreach ($tables as $table) {
         if ($table['m_table'] == 'sessions') {
             continue;
         }
         // HEAP, so can't be repaired
         $table = get_table_prefix() . $table['m_table'];
         // Check/Repair
         $result = mysql_query('CHECK TABLE ' . $table . ' FAST', $db);
         echo mysql_error($db);
         mysql_data_seek($result, mysql_num_rows($result) - 1);
         $status_row = mysql_fetch_assoc($result);
         if ($status_row['Msg_type'] != 'status') {
             $out->attach(paragraph(do_lang_tempcode('TABLE_ERROR', escape_html($table), escape_html($status_row['Msg_type']), array(escape_html($status_row['Msg_text']))), 'dfsdgdsgfgd'));
             $result2 = mysql_query('REPAIR TABLE ' . $table, $db);
             mysql_data_seek($result2, mysql_num_rows($result2) - 1);
             $status_row_2 = mysql_fetch_assoc($result2);
             $out->attach(paragraph(do_lang_tempcode('TABLE_FIXED', escape_html($table), escape_html($status_row_2['Msg_type']), array(escape_html($status_row_2['Msg_text']))), 'dfsdfgdst4'));
         }
         // Optimise
         mysql_unbuffered_query('OPTIMIZE TABLE ' . $table, $db);
     }
     return $out;
 }
Ejemplo n.º 6
0
 function query($sql, $unbuffered = false)
 {
     if (strlen($sql) > FORUM_DATABASE_QUERY_MAXIMUM_LENGTH) {
         exit('Insane query. Aborting.');
     }
     if (defined('FORUM_SHOW_QUERIES') || defined('FORUM_DEBUG')) {
         $q_start = forum_microtime();
     }
     if ($unbuffered) {
         $this->query_result = @mysql_unbuffered_query($sql, $this->link_id);
     } else {
         $this->query_result = @mysql_query($sql, $this->link_id);
     }
     if ($this->query_result) {
         if (defined('FORUM_SHOW_QUERIES') || defined('FORUM_DEBUG')) {
             $this->saved_queries[] = array($sql, sprintf('%.5f', forum_microtime() - $q_start));
         }
         ++$this->num_queries;
         return $this->query_result;
     } else {
         if (defined('FORUM_SHOW_QUERIES') || defined('FORUM_DEBUG')) {
             $this->saved_queries[] = array($sql, 0);
         }
         return false;
     }
 }
 function select($query, $class = 'recordset')
 {
     if (!$this->con_id) {
         return false;
     }
     if ($class == '' || !class_exists($class)) {
         $class = 'recordset';
     }
     $cur = mysql_unbuffered_query($query, $this->con_id);
     if ($cur) {
         # Insertion dans le reccordset
         $i = 0;
         $arryRes = array();
         while ($res = mysql_fetch_row($cur)) {
             for ($j = 0; $j < count($res); $j++) {
                 $arryRes[$i][strtolower(mysql_field_name($cur, $j))] = $res[$j];
             }
             $i++;
         }
         return new $class($arryRes);
     } else {
         $this->setError();
         return false;
     }
 }
function importar_ctw($db = "ctw10005.dbf", $id = "2007")
{
    //elimina la anterior
    mysql_unbuffered_query("TRUNCATE compacw_importados");
    $pathdbase = CTW_PATH . "/" . $db;
    //$db = dbase_open($ipdbase . $dirdbase . $nombredb . $db, 0);
    $rs = dbase_open($pathdbase, 2);
    //echo $pathdbase;
    $num_rows = dbase_numrecords($rs);
    //$o_num_rows = dbase_numrecords ($rs);
    //$num_rows = 100000;				//Eliminar la Consulta a 50000
    for ($i = 1; $i <= $num_rows; $i++) {
        $field = dbase_get_record_with_names($rs, $i);
        if (trim($field["EJE"]) == $id and trim($field["TIPO"]) == 1) {
            //
            $values_sql = " ('" . $field["CUENTA"] . "', " . $field["IMP1"] . ") ";
            $sql_ex = "INSERT INTO compacw_importados(cuenta, saldo) VALUES " . $values_sql;
            mysql_unbuffered_query($sql_ex);
            //
        }
    }
    //
    //dbase_pack($rs);
    dbase_close($rs);
    echo "<p>DATOS IMPORTADOS:  " . date("H:i:s") . " HRS </p>";
}
Ejemplo n.º 9
0
function QuerySql($match_way, $query_way, $search_text, $Fields)
{
    $result = NULL;
    $row = NULL;
    switch ($match_way) {
        case '1':
            $match_way_sql = "= '" . $search_text . "';";
            break;
        case '2':
            $match_way_sql = " LIKE '%" . $search_text . "%';";
            break;
    }
    $getID = array();
    $flag = 0;
    foreach ($Fields as $value) {
        $q = "SELECT id FROM" . " `" . $query_way . "` " . "WHERE" . " `" . $Fields[$flag] . "`" . $match_way_sql;
        //echo $q."<br/>";
        $result = mysql_unbuffered_query($q);
        while ($row = mysql_fetch_row($result)) {
            $str .= $row[0] . ",";
        }
        //echo $str."<br/>";
        //echo "---".$flag."---";
        $flag++;
    }
    $str = substr($str, 0, strlen($str) - 1);
    $sql = "SELECT * from " . $query_way . " where id in (" . $str . ");";
    return $sql;
}
Ejemplo n.º 10
0
function cs_sql_connect($cs_db, $test = 0)
{
    $error = '';
    if (!extension_loaded('mysql')) {
        $error = 'PHP extension mysql must be activated!';
    } else {
        $connect = mysql_connect($cs_db['place'], $cs_db['user'], $cs_db['pwd']) or $error = mysql_error();
    }
    if (empty($error)) {
        mysql_select_db($cs_db['name']) or $error = mysql_error($connect);
    }
    global $cs_main;
    $sql_charset = strtolower($cs_main['charset']);
    if (empty($error) and $sql_charset == 'utf-8') {
        # since php 5.2.3 - depends on mysql libs, too
        if (function_exists('mysql_set_charset')) {
            mysql_set_charset('utf8', $connect);
        } else {
            mysql_unbuffered_query("SET NAMES 'utf8'", $connect) or $error = mysql_error();
        }
    }
    if (empty($test) and empty($error)) {
        return $connect;
    } elseif (empty($test)) {
        cs_error_sql(__FILE__, 'cs_sql_connect', $error, 1);
    } else {
        return $error;
    }
}
Ejemplo n.º 11
0
 function query($query, $bypass_error = FALSE, $unbufferd = false)
 {
     $this->querytime = get_microtime();
     $this->query_result = $unbufferd ? mysql_unbuffered_query($query, $this->connect_id) : mysql_query($query, $this->connect_id);
     if ($this->query_result) {
         return $this->query_result;
     } else {
         if ((mysql_errno() == 1030 && strpos(mysql_error(), '127') || mysql_errno() == 1034 || mysql_errno() == 1035) && preg_match('#(INTO|FROM)\\s+([a-z_]+)#i', $query, $match) && mysql_query('REPAIR TABLE ' . $match[2], $this->connect_id)) {
             $this->query_result = $unbufferd ? mysql_unbuffered_query($query, $this->connect_id) : mysql_query($query, $this->connect_id);
             if ($this->query_result) {
                 return $this->query_result;
             }
         } else {
             if (mysql_errno() == 1062 && preg_match('#ALTER\\s+TABLE\\s+([a-z_]+)\\s+ADD\\s+PRIMARY\\s+KEY\\s+\\(([a-z_]+)\\)#i', $query, $table) && preg_match("#Duplicate\\s+entry\\s+'(.*)'\\s+for\\s+key#i", mysql_error(), $entry) && mysql_query("DELETE FROM {$table['1']} WHERE {$table['2']} LIKE '{$entry['1']}%' LIMIT " . (mysql_num_rows(mysql_query("SELECT {$table['2']} FROM {$table['1']} WHERE {$table['2']} LIKE '{$entry['1']}%'", $this->connect_id)) - 1), $this->connect_id) || mysql_errno() == 1062 && preg_match('#CREATE\\s+UNIQUE\\s+INDEX\\s+([a-z_]+)\\s+ON\\s+([a-z_]+)\\s+\\(([a-z_]+)\\)#i', $query, $table) && preg_match("#Duplicate\\s+entry\\s+'(.*)'\\s+for\\s+key#i", mysql_error(), $entry) && mysql_query("DELETE FROM {$table['2']} WHERE {$table['3']} LIKE '{$entry['1']}%' LIMIT " . (mysql_num_rows(mysql_query("SELECT {$table['3']} FROM {$table['2']} WHERE {$table['3']} LIKE '{$entry['1']}%'", $this->connect_id)) - 1), $this->connect_id)) {
                 return $this->query($query, $bypass_error, $unbufferd);
             } else {
                 if (mysql_errno() == 1007 && preg_match('#CREATE\\s+DATABASE\\s+#i', $query)) {
                     return true;
                 }
             }
         }
     }
     if ($bypass_error) {
         return NULL;
     } else {
         $this->show_error("While executing query \"{$query}\"\n\nthe following error occured: " . mysql_error());
     }
 }
Ejemplo n.º 12
0
 function query($sql, $unbuffered = false)
 {
     if (strlen($sql) > 140000) {
         exit('Insane query. Aborting.');
     }
     if (defined('OPENLD_SHOW_QUERIES')) {
         $q_start = microtime_float();
     }
     if ($unbuffered) {
         $this->query_result = @mysql_unbuffered_query($sql, $this->link_id);
     } else {
         $this->query_result = @mysql_query($sql, $this->link_id);
     }
     if ($this->query_result) {
         if (defined('OPENLD_SHOW_QUERIES')) {
             $this->saved_queries[] = array($sql, sprintf('%.5f', get_microtime() - $q_start));
         }
         ++$this->num_queries;
         return $this->query_result;
     } else {
         if (defined('OPENLD_SHOW_QUERIES')) {
             $this->saved_queries[] = array($sql, 0);
         }
         return false;
     }
 }
Ejemplo n.º 13
0
 function query($sql, $unbuffered = false)
 {
     if (defined('FORUM_SHOW_QUERIES')) {
         $q_start = get_microtime();
     }
     if ($unbuffered) {
         $this->query_result = @mysql_unbuffered_query($sql, $this->link_id);
     } else {
         $this->query_result = @mysql_query($sql, $this->link_id);
     }
     if ($this->query_result) {
         if (defined('FORUM_SHOW_QUERIES')) {
             $this->saved_queries[] = array($sql, sprintf('%.5f', get_microtime() - $q_start));
         }
         ++$this->num_queries;
         return $this->query_result;
     } else {
         if (defined('FORUM_SHOW_QUERIES')) {
             $this->saved_queries[] = array($sql, 0);
         }
         $this->error_no = @mysql_errno($this->link_id);
         $this->error_msg = @mysql_error($this->link_id);
         // Rollback transaction
         if ($this->in_transaction) {
             mysql_query('ROLLBACK', $this->link_id);
         }
         --$this->in_transaction;
         return false;
     }
 }
Ejemplo n.º 14
0
 function rewind()
 {
     global $MYSQL_FORCE_INDEXES;
     $this->Clear();
     $list = "";
     foreach ($this->ids as $id) {
         $list .= "v{$id} AS v{$id}, ";
     }
     $table = $this->cache->GetTableName(0, $this->postfix);
     $sql = $this->ivl->GetSQL($this->cache, $table, $this->limit, $this->use_subseconds, isset($this->sequence) ? $this->sequence : false, $this->sampling);
     if ($MYSQL_FORCE_INDEXES) {
         if ($sql['index']) {
             sprintf($idx_fix, "FORCE INDEX (%s)", $sql['index']);
         } else {
             $idx_fix = "FORCE INDEX (PRIMARY)";
         }
     } else {
         $idx_fix = "";
     }
     $list .= $sql['list'];
     $cond =& $sql['cond'];
     $sort =& $sql['sort'];
     $limit =& $sql['limit'];
     $join =& $sql['join'];
     $this->res = mysql_unbuffered_query("SELECT {$list} FROM `{$table}` {$idx_fix} {$join} {$cond} {$sort} {$limit}", $this->cache->dbh);
     if (!$this->res) {
         throw new ADEIException(translate("SELECT request '%s'  on CACHE table '%s' is failed. MySQL error: %s", "SELECT {$list} FROM `{$table}` {$idx_fix} {$join} {$cond} {$sort} {$limit}", $table, mysql_error($this->cache->dbh)));
     }
     $this->next();
 }
 function query($sql, $unbuffered = false)
 {
     if (strlen($sql) > 140000) {
         exit('Insane query. Aborting.');
     }
     if (defined('FORUM_SHOW_QUERIES') || defined('FORUM_DEBUG')) {
         $q_start = forum_microtime();
     }
     if ($unbuffered) {
         $this->query_result = @mysql_unbuffered_query($sql, $this->link_id);
     } else {
         $this->query_result = @mysql_query($sql, $this->link_id);
     }
     if ($this->query_result) {
         if (defined('FORUM_SHOW_QUERIES') || defined('FORUM_DEBUG')) {
             $this->saved_queries[] = array($sql, sprintf('%.5f', forum_microtime() - $q_start));
         }
         ++$this->num_queries;
         return $this->query_result;
     } else {
         if (defined('FORUM_SHOW_QUERIES') || defined('FORUM_DEBUG')) {
             $this->saved_queries[] = array($sql, 0);
         }
         if ($this->in_transaction) {
             mysql_query('ROLLBACK', $this->link_id);
         }
         --$this->in_transaction;
         return false;
     }
 }
Ejemplo n.º 16
0
 function unbuffered_query($query_string)
 {
     $selecting_result = mysql_unbuffered_query($query_string);
     if (!$selecting_result) {
         $this->error("False query == {$query_string}");
     }
     return $selecting_result;
 }
Ejemplo n.º 17
0
 public function unbuffered_query($sql)
 {
     $q = mysql_unbuffered_query($sql, $this->mysql);
     if ($q === false) {
         throw new dbException(mysql_error($this->mysql) . "\nSQL: {$sql}", mysql_errno($this->mysql));
     }
     return $q;
 }
Ejemplo n.º 18
0
 public function vxUpdateComments()
 {
     $sql = "SELECT COUNT(*) FROM babel_weblog_entry_comment WHERE bec_eid = {$this->bge_id} AND bec_status = 1";
     $count = mysql_result(mysql_query($sql), 0, 0);
     $sql = "UPDATE babel_weblog_entry SET bge_comments = {$count} WHERE bge_id = {$this->bge_id}";
     mysql_unbuffered_query($sql);
     return true;
 }
Ejemplo n.º 19
0
	/**
	 * @param $sql string
	 * @return resource
	 */
	protected function doQuery( $sql ) {
		if ( $this->bufferResults() ) {
			$ret = mysql_query( $sql, $this->mConn );
		} else {
			$ret = mysql_unbuffered_query( $sql, $this->mConn );
		}
		return $ret;
	}
function d2ac473559323489421747601740046c($strid = "99|99")
{
    $datos = explode("|", $strid);
    $solicitud = $datos[0];
    $sql_u = "UPDATE creditos_solicitud SET estatus_actual=50 WHERE numero_solicitud={$solicitud}";
    $rs = mysql_unbuffered_query($sql_u);
    return "ACTUALIZACION DE REGISTRO SATISFACTORIO - CODIGO {$datos['0']} | {$datos['1']}";
}
Ejemplo n.º 21
0
	function query_ubuf($query){
		$res = mysql_unbuffered_query($query, $this->conn);
		if (!$res){
			throw new Exception("Query error: " . $this->error() . "\n\nSQL: " . $query);
		}
		
		return new knjdb_result($this->knjdb, $this, $res);
	}
Ejemplo n.º 22
0
 public static function fetch($sql)
 {
     //echo $sql;
     $fp = fopen("log.txt", "a");
     fwrite($fp, "SQL:" . $sql . "\r\n");
     fclose($fp);
     self::$query = mysql_unbuffered_query($sql, self::$db);
 }
 protected function _query($sql, $buffered = true)
 {
     if ($buffered) {
         return mysql_query($sql, $this->connection);
     } else {
         return mysql_unbuffered_query($sql, $this->connection);
     }
 }
Ejemplo n.º 24
0
 function CreateDatabase($database, $prefix)
 {
     $sql = $this->getSQLFromFile($database, $prefix);
     foreach ($sql as $q) {
         mysql_unbuffered_query($q, $this->_dbpointer);
     }
     return $this;
 }
Ejemplo n.º 25
0
	function rawExec($s) {
		$tmpRes = @mysql_unbuffered_query($s, $this->_conn);
		if ($tmpRes === false) {
			throw new Exception("Error executing query: " . mysql_error($this->_conn));
		} # if
		
		return $tmpRes;
	} # rawExec
Ejemplo n.º 26
0
 public function unbufferedQuery(IDatabaseQuery $query)
 {
     $this->connect();
     $result = mysql_unbuffered_query($query, $this->dbhandle);
     if (!is_resource($result)) {
         throw new DatabaseException('query failed!', 503);
     }
     return new mysqlResult($result);
 }
Ejemplo n.º 27
0
 function unbuffered_query($query)
 {
     $res = mysql_unbuffered_query($query, $this->con);
     if ($res === false) {
         return false;
     }
     $this->cache[] = $res;
     return $res;
 }
Ejemplo n.º 28
0
 public function vxSetupWeightV2EX()
 {
     mysql_unbuffered_query("UPDATE babel_node SET nod_weight = 100 WHERE nod_name = 'limbo'");
     mysql_unbuffered_query("UPDATE babel_node SET nod_weight = 1000 WHERE nod_name = 'mechanus'");
     mysql_unbuffered_query("UPDATE babel_node SET nod_weight = 10000 WHERE nod_name = 'thegraywaste'");
     mysql_unbuffered_query("UPDATE babel_node SET nod_weight = 10 WHERE nod_name = 'sigil'");
     mysql_unbuffered_query("UPDATE babel_node SET nod_weight = 1 WHERE nod_name = 'elysium'");
     mysql_unbuffered_query("UPDATE babel_node SET nod_weight = 500 WHERE nod_name = 'theriveroceanus'");
 }
Ejemplo n.º 29
0
 function query_unbuff($q)
 {
     // run it
     $this->lastq = @mysql_unbuffered_query($q, $this->conn) or $this->error_message("Query Error: " . mysql_error() . "\n");
     // increment query count
     $this->query_count++;
     // return result
     return $this->lastq;
 }
Ejemplo n.º 30
0
 /**
  * Run a query on the currently connected database server.
  * @param $query The SQL query to run.
  * @return resource The results of <code>mysql_unbuffered_query()</code>, which represents
  * a resource that can be used to fetch the returned rows from the query, or <code>false</code>
  * if error.
  */
 public function runQuery($query)
 {
     $result = @mysql_unbuffered_query($query, $this->mysqlCon);
     if ($result === false) {
         throw new Exception('Database query failed: ' . mysql_error($this->mysqlCon));
     }
     $this->affectedRows = mysql_affected_rows($this->mysqlCon);
     $this->identity = mysql_insert_id($this->mysqlCon);
     return $result;
 }