• Blogs (9)
    • 📱 236 - 992 - 3846

      đź“§ jxjwilliam@gmail.com

    • Version: ‍🚀 1.1.0
  • MDB2: Common functions summary

    Blogs20112011-09-10


    As PEAR’s core libary, MDB2 has hundreds of functions. Sometimes easily to be confused. e.g, queryOne(), fetchOne(), getOne(), they seem to be very similiar. How to distinguish them, and when to use them?

    PHP Pear’s MDB2 has not much documents and examples, here I list 2 are very useful references:

    I also extract and summarize the functions which are most often used, easy confusion:

    1. querying

    function describe
    query in file MDB2.php, method MDB2_Driver_Common::query()
    Send a query to the database and return any results
    queryAll in file MDB2.php, method MDB2_Driver_Common::queryAll()
    Execute the specified query, fetch all the rows of the result set into a two dimensional array and then frees the result set.
    queryRow in file MDB2.php, method MDB2_Driver_Common::queryRow()
    Execute the specified query, fetch the values from the first row of the result set into an array and then frees the result set.
    queryCol in file MDB2.php, method MDB2_Driver_Common::queryCol()
    Execute the specified query, fetch the value from the first column of each row of the result set into an array and then frees the result set.
    queryOne in file MDB2.php, method MDB2_Driver_Common::queryOne()
    Execute the specified query, fetch the value from the first column of the first row of the result set and then frees the result set.

    2. results

    function describe
    fetchAll in file MDB2.php, method MDB2_Result_Common::fetchAll()
    Fetch and return all rows from the current row pointer position
    fetchRow in file MDB2.php, method MDB2_Result_Common::fetchRow()
    Fetch and return a row of data
    fetchCol in file MDB2.php, method MDB2_Result_Common::fetchCol()
    Fetch and return a column from the current row pointer position
    fetchOne in file MDB2.php, method MDB2_Result_Common::fetchOne()
    fetch single column from the next row from a result set

    3. gets

    function describe
    getAll in file Extended.php, method MDB2_Extended::getAll()
    Fetch all the rows returned from a query.
    getRow in file Extended.php, method MDB2_Extended::getRow()
    Fetch the first row of data returned from a query. Takes care of doing the query and freeing the results when finished.
    getCol in file Extended.php, method MDB2_Extended::getCol()
    Fetch a single column from a result set and return it as an indexed array.
    getOne in file Extended.php, method MDB2_Extended::getOne()
    Fetch the first column of the first row of data returned from a query.
    getColumnNames in file MDB2.php, method MDB2_Result_Common::getColumnNames()
    Retrieve the names of columns returned by the DBMS in a query result or from the cache.

    4. misc

    function describe
    numCols in file MDB2.php, method MDB2_Result_Common::numCols()
    Count the number of columns returned by the DBMS in a query result.
    numRows in file MDB2.php, method MDB2_Result_Common::numRows()
    Returns the number of rows in a result object
    escape in file MDB2.php, method MDB2_Driver_Common::escape()
    Quotes a string so it can be safely used in a query. It will quote the text so it can safely be used within a query.
    exec in file MDB2.php, method MDB2_Driver_Common::exec()
    Execute a manipulation query to the database and return the number of affected rows
    rowCount in file MDB2.php, method MDB2_Result_Common::rowCount()
    Returns the actual row number that was last fetched (count from 0), used in CRUD.
    lastInsertID in file MDB2.php, method MDB2_Driver_Common::lastInsertID()
    Returns the autoincrement ID if supported or $id or fetches the current ID in a sequence called: $table.(empty($field) ? ” : ’_’.$field)
    isError in file MDB2.php, method MDB2::isError()
    Tell whether a value is a MDB2 error.