Foros del Web » Programando para Internet » PHP »

[|PREFIX|] en un query a Mysql?

Estas en el tema de [|PREFIX|] en un query a Mysql? en el foro de PHP en Foros del Web. loading........ Estuve viendo algunas class y vi algo que no entiendo. en un insert a mysql basado en un array se usa [|PREFIX|] .... mmm ...
  #1 (permalink)  
Antiguo 16/08/2009, 16:27
Avatar de MaBoRaK  
Fecha de Ingreso: abril-2003
Ubicación: La Paz - Bolivia
Mensajes: 2.003
Antigüedad: 21 años
Puntos: 35
[|PREFIX|] en un query a Mysql?

loading........


Estuve viendo algunas class y vi algo que no entiendo. en un insert a mysql basado en un array se usa [|PREFIX|] .... mmm y no encuentro documentacion.

aca el método:

Código PHP:
/**
     * Build and execute a database insert query from an array of keys/values.
     *
     * @param string The table to insert into.
     * @param array Associative array of key/value pairs to insert.
     * @param bool TRUE to interpret NULL as being database NULL, FALSE to mean an empty string
     * @return mixed Insert ID or true on successful insertion, false on failure.
     */
    
function InsertQuery($table$values$useNullValues=false)
    {
        
$keys array_keys($values);
        
$fields implode($this->EscapeChar.",".$this->EscapeChar$keys);

        foreach (
$keys as $key) {

            if (
$useNullValues) {
                if (
is_null($values[$key])) {
                    
$values[$key] = "NULL";
                } else {
                    
$values[$key] = "'" $this->Quote($values[$key]) . "'";
                }
            } else {
                
$values[$key] = "'" $this->Quote($values[$key]) . "'";
            }
        }

        
$values implode(","$values);
//aqui aqui
        
$query sprintf('INSERT INTO %1$s[|PREFIX|]%2$s%1$s (%1$s%3$s%1$s) VALUES (%4$s)'$this->EscapeChar$table$fields$values);
        if (
$this->Query($query)) {
            
// only return last id if it contains a valid value, otherwise insertquery reports as failed if it returns a false value (0, null etc)
            
if ((int)$this->LastId() > 0) {
                return 
$this->LastId();
            }
            else {
                return 
true;
            }
        }
        else {
            return 
false;
        }
    } 
Que opinan que sea?

gracias.


connection closed.
__________________

Maborak Technologies
  #2 (permalink)  
Antiguo 16/08/2009, 16:30
Avatar de MaBoRaK  
Fecha de Ingreso: abril-2003
Ubicación: La Paz - Bolivia
Mensajes: 2.003
Antigüedad: 21 años
Puntos: 35
Respuesta: [|PREFIX|] en un query a Mysql?

loading.........


Sorry ya vi lo que es... en su método Query, lo reemplazan por su el prefix de sus tablas.

Código PHP:
/**
    * Query
    * This function will run a query against the database and return the result of the query.
    *
    * @param String $query The query to run.
    *
    * @see LogQuery
    * @see SetError
    *
    * @return Mixed Returns false if the query is empty or if there is no result. Otherwise returns the result of the query.
    */
    
function Query($query='')
    {
        
// if we're retrying a query, we have to kill the old connection and grab it again.
        // if we don't, we get a cached connection which won't work.
        
if ($this->_retry) {
            
$this->Connect();
        }

        
// Trim query
        
$query trim($query);

        if (!
$query) {
            
$this->_retry false;
            
$this->SetError('Query passed in is empty');
            return 
false;
        }

        if (!
$this->connection) {
            
$this->_retry false;
            
$this->SetError('No valid connection');
            return 
false;
        }

        if (
$this->TablePrefix !== null) {
            
$query str_replace("[|PREFIX|]"$this->TablePrefix$query);
        } else {
            
$query str_replace("[|PREFIX|]"''$query);
        }

        
$this->NumQueries++;

        if (
$this->TimeLog !== null || $this->StoreQueryList ==  true) {
            
$timestart $this->GetTime();
        }

        if (!
$this->_unbuffered_query) {
            
$result mysql_query($query$this->connection);
        } else {
            
$result mysql_unbuffered_query($query$this->connection);
            
$this->_unbuffered_query false;
        }

        if (
$this->TimeLog !== null) {
            
$timeend $this->GetTime();
            
$this->TimeQuery($query$timestart$timeend);
        }

        if(
$this->StoreQueryList) {
            if(!isset(
$timeend)) {
                
$timeend $this->GetTime();
            }
            
$this->QueryList[] = array(
                
"Query" => $query,
                
"ExecutionTime" => $timeend-$timestart
            
);
        }

        if (
$this->QueryLog !== null) {
            if (
$this->_retry) {
                
$this->LogQuery("*** Retry *** Result type: " gettype($result) . "; value: " $result "\t" $query);
            } else {
                
$this->LogQuery("Result type: " gettype($result) . "; value: " $result "\t" $query);
            }
        }

        if (!
$result) {
            
$error mysql_error($this->connection);
            
$errno mysql_errno($this->connection);

            if (
$this->ErrorLog !== null) {
                
$this->LogError($query$error);
            }

            
$this->SetError($errorE_USER_ERROR$query);

            
// we've already retried? don't try again.
            // or if the error is not '2006', then don't bother going any further.
            
if ($this->_retry || $errno !== 2006) {
                
$this->_retry false;
                return 
false;
            }

            
// error 2006 is 'server has gone away'
            // http://dev.mysql.com/doc/refman/5.0/en/error-messages-client.html
            
if ($errno === 2006) {
                
$this->_retry true;
                return 
$this->Query($query);
            }
        }

        
// make sure we set the 'retry' flag back to false if we are returning a result set.
        
$this->_retry false;
        return 
$result;
    } 

please cierren el post :p



connection closed.
__________________

Maborak Technologies
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 07:31.