MysqliDb::rawQuery PHP Method

rawQuery() public method

Execute raw SQL query.
public rawQuery ( string $query, array $bindParams = null ) : array
$query string User-provided query to execute.
$bindParams array Variables array to bind to the SQL statement.
return array Contains the returned rows from the query.
    public function rawQuery($query, $bindParams = null)
    {
        $params = array('');
        // Create the empty 0 index
        $this->_query = $query;
        $stmt = $this->_prepareQuery();
        if (is_array($bindParams) === true) {
            foreach ($bindParams as $prop => $val) {
                $params[0] .= $this->_determineType($val);
                array_push($params, $bindParams[$prop]);
            }
            call_user_func_array(array($stmt, 'bind_param'), $this->refValues($params));
        }
        $stmt->execute();
        $this->count = $stmt->affected_rows;
        $this->_stmtError = $stmt->error;
        $this->_stmtErrno = $stmt->errno;
        $this->_lastQuery = $this->replacePlaceHolders($this->_query, $params);
        $res = $this->_dynamicBindResults($stmt);
        $this->reset();
        return $res;
    }

Usage Example

コード例 #1
1
/**
 * @descr Obtiene las comentarios
 */
function getComentarios($post_id)
{
    $db = new MysqliDb();
    $results = $db->rawQuery('SELECT
    c.post_comentario_id,
    c.post_id,
    c.titulo,
    c.detalles,
    c.parent_id,
    c.creador_id,
    c.votos_up,
    c.votos_down,
    c.fecha,
    u.nombre,
    u.apellido
FROM
    posts_comentarios c
        LEFT JOIN
    usuarios u ON u.usuario_id = c.creador_id
WHERE
    c.post_id = ' . $post_id . '
    order by c.post_comentario_id;');
    echo json_encode($results);
}
All Usage Examples Of MysqliDb::rawQuery