MySQL::SelectRows PHP Méthode

SelectRows() public méthode

Gets rows in a table based on a WHERE filter
public SelectRows ( string $tableName, array $whereArray = null, array/string $columns = null, array/string $sortColumns = null, boolean $sortAscending = true, integer/string $limit = null ) : boolean
$tableName string The name of the table
$whereArray array (Optional) An associative array containing the column names as keys and values as data. The values must be SQL ready (i.e. quotes around strings, formatted dates, ect)
$columns array/string
$sortColumns array/string
$sortAscending boolean (Optional) TRUE for ascending; FALSE for descending This only works if $sortColumns are specified
$limit integer/string
Résultat boolean Returns records on success or FALSE on error
    public function SelectRows($tableName, $whereArray = null, $columns = null, $sortColumns = null, $sortAscending = true, $limit = null)
    {
        $this->ResetError();
        if (!$this->IsConnected()) {
            $this->SetError("No connection");
            return false;
        } else {
            $sql = self::BuildSQLSelect($tableName, $whereArray, $columns, $sortColumns, $sortAscending, $limit);
            // Execute the UPDATE
            if (!$this->Query($sql)) {
                return $this->last_result;
            } else {
                return true;
            }
        }
    }

Usage Example

/** Lấy đường dẫn nhóm media */
function get_media_group_part($id = 0, $i = 1, $deepest = FALSE)
{
    $hmdb = new MySQL(true, DB_NAME, DB_HOST, DB_USER, DB_PASSWORD, DB_CHARSET);
    if (!is_numeric($id)) {
        $tableName = DB_PREFIX . 'media_groups';
        $whereArray = array('folder' => MySQL::SQLValue($id));
        $hmdb->SelectRows($tableName, $whereArray);
        $row = $hmdb->Row();
        $id = $row->id;
    }
    $bre = array();
    $sub_bre = FALSE;
    if ($deepest == FALSE) {
        $deepest = $id;
    }
    $tableName = DB_PREFIX . 'media_groups';
    $whereArray = array('id' => MySQL::SQLValue($id));
    $hmdb->SelectRows($tableName, $whereArray);
    $row = $hmdb->Row();
    $num_rows = $hmdb->RowCount();
    if ($num_rows != 0) {
        $this_id = $row->id;
        $folder = $row->folder;
        $parent = $row->parent;
        $bre['level_' . $i] = $folder;
        if ($parent != '0') {
            $inew = $i + 1;
            $sub_bre = get_media_group_part($parent, $inew, $deepest);
        }
    }
    if (is_array($sub_bre)) {
        $bre = array_merge($bre, $sub_bre);
    }
    krsort($bre);
    $part = implode("/", $bre);
    if ($deepest == $id) {
        return $part;
    } else {
        return $bre;
    }
}
All Usage Examples Of MySQL::SelectRows