select Back | Forward | Home

'Language Reference'

User Functions

Database Functions

Data Manipulation Functions
  • select

  • insert

  • update

  • delete

  • execute


  • Table Functions

    Error Handling Functions

    << Last Section ( Data Manipulation Functions ) select Next Section ( insert ) >>
    Usage mixed select ( array( 'table' => $table [, 'select' => $selectCols[, 'db' => $db [, 'where' => $where [, 'limit' => $limit [, 'orderby' => $orderb[, $distinct = $column]]]]] ) )
    Purpose To select data from a txtSQL table
    Availability txtSQL >= 2.2.2 RC2

    This function will retrieve data that matches the $where clause; if no $where clause is given, all rows match, and thus will be returned. If $selectCols is specified, then txtSQL will only select those columns. $selectCols should be an array with the following structure
         array ( col1, col2 ... )

    The search will look inside the selected database if no $db is defined, and will return rows according to the limit clause. If $orderby is specified, then the results will be sorted according to the orderby clause. If $distinct is set to TRUE, then the any repeated values for that $column will be deleted.

    Important- To achieve the same results as this function before txtSQL 2.2.2 RC2, use the execute() function
    Note- The DISTINCT feature was added in txtSQL 2.2 Final release
    Note- For more information on defining a where clause, see the 'where clause' section, or for defining a limit clause, see how to create a limit clause section
    Note- If no database is selected, and no $db is given, txtSQL will issue an error

    Example 15: select() Copy to Clipboard
    <?php
    $data
    = $sql->select(array(
        
    'db'      => 'testDB',
        
    'table'   => 'testTable',
        
    'where'   => array('strtolower(somecolumn) = value'),
        
    'limit'   => array(10, 19),
        
    'orderby' => array('id', 'ASC')
        ));

    foreach (
    $data as $key => $row )
    {
        print
    'Row '.$key.': '.print_r($row,1)."<br>\n";
    }
    ?>

    User-Contributed Comments for:
    select()
    FarazAli <Faraz87 at comcast dot net>
    July 30, 2004, 11:19 pm
    You can specify what columns you want to select by adding something like

    'select' => array('column', 'column2' ...)

    to the array.

    Example:
    $sql->select(array(
        'select' => array('id', 'name'),
        'table'  => 'data',
        'db'     => 'testDB'
    ));