This is just a simple article to references most of the simple ADOdb functions I use in QWcrm and what they do:
Smarty Call
$smarty->assign('currency_sym', get_company_details($db));
The Basic Function
I will use this function for the demo. This function just returns all of the company information or a single item.
function get_company_details($db, $item = null){
global $smarty;
$sql = 'SELECT * FROM '.PRFX.'TABLE_COMPANY';
if(!$rs = $db->execute($sql)){
force_error_page($_GET['page'], 'database', __FILE__, __FUNCTION__, $db->ErrorMsg(), $sql, $smarty->get_template_vars('translate_system_include_error_message_function_'.__FUNCTION__.'_failed'));
exit;
} else {
if($item === null){
return $rs->GetArray();
} else {
return $rs->fields[$item];
}
}
}
The Results
I will be changing the line and listing the results
return $rs->GetArray();
$rs->GetArray();
Array
(
[0] => Array
(
[0] => QuantumWarp
[NAME] => QuantumWarp
[1] => 123456
[NUMBER] => 123456
[2] => The Gurking
[ADDRESS] => The Gurking
[3] => London
[CITY] => London
[4] => Greater London
[STATE] => Greater London
[5] => LA1 W10
[ZIP] => LA1 W10
[6] => AF
[COUNTRY] => GB
[7] => 123456
[PHONE] => 123456
[8] => 123456
[MOBILE] => 123456
[9] => 123456
[FAX] => 123456
[10] =>
[EMAIL] =>
[11] => £
[CURRENCY_SYMBOL] => £
[12] => GPB
[CURRENCY_CODE] => GPB
[13] => %d/%m/%Y
[DATE_FORMAT] => %d/%m/%Y
[14] => media/logo.png
[LOGO] => media/logo.png
[15] =>
[WWW] =>
[16] => 10
[OPENING_HOUR] => 10
[17] => 0
[OPENING_MINUTE] => 0
[18] => 17
[CLOSING_HOUR] => 17
[19] => 0
[CLOSING_MINUTE] => 0
[20] => 3.50
[TAX_RATE] => 3.50
[21] => <p>welcome</p>
[WELCOME_MSG] => <p>welcome</p>
[22] => <p>thanks</p>
[INVOICE_MSG] => <p>thanks</p>
)
)
- ADODB Manual - Link 1 - Generate a 2-dimensional array of records from the current cursor position, indexed from 0 to $number_of_rows - 1. If $number_of_rows is undefined, till EOF.
- Returns all rows.
$rs->GetRows();
- Generate a 2-dimensional array of records from the current cursor position. Synonym for GetArray() for compatibility with Microsoft ADO.
- Returns all rows.
$rs->GetAssoc();
Array
(
[QuantumWarp] => Array
(
[NAME] => QuantumWarp
[0] => 123456
[NUMBER] => 123456
[1] => The Gurking
[ADDRESS] => The Gurking
[2] => London
[CITY] => London
[3] => Greater London
[STATE] => Greater London
[4] => LA1 W10
[ZIP] => LA1 W10
[5] => AF
[COUNTRY] => GB
[6] => 123456
[PHONE] => 123456
[7] => 123456
[MOBILE] => 123456
[8] => 123456
[FAX] => 123456
[9] =>
[EMAIL] =>
[10] => £
[CURRENCY_SYMBOL] => £
[11] => GPB
[CURRENCY_CODE] => GPB
[12] => %d/%m/%Y
[DATE_FORMAT] => %d/%m/%Y
[13] => media/logo.png
[LOGO] => media/logo.png
[14] =>
[WWW] =>
[15] => 10
[OPENING_HOUR] => 10
[16] => 0
[OPENING_MINUTE] => 0
[17] => 17
[CLOSING_HOUR] => 17
[18] => 0
[CLOSING_MINUTE] => 0
[19] => 3.50
[TAX_RATE] => 3.50
[20] => <p>welcome</p>
[WELCOME_MSG] => <p>welcome</p>
[21] => <p>thanks</p>
[INVOICE_MSG] => <p>thanks</p>
)
)
- ADODB Manual - Link 1 - Generates an associative array from the recordset. Note that is this function is also available in the connection object. More details can be found there.
- ADODB Manual - Link 2 - Returns an associative array for the given query $sql with optional bind parameters in $inputarr. If the number of columns returned is greater to two, a 2-dimensional array is returned, with the first column of the recordset becomes the keys to the rest of the rows. If the columns is equal to two, a 1-dimensional array is created, where the the keys directly map to the values (unless $force_array is set to true, when an array is created for each value).
- Returns all rows.
$rs->FetchRow();
Array
(
[0] => QuantumWarp
[NAME] => QuantumWarp
[1] => 123456
[NUMBER] => 123456
[2] => The Gurking
[ADDRESS] => The Gurking
[3] => London
[CITY] => London
[4] => Greater London
[STATE] => Greater London
[5] => LA1 W10
[ZIP] => LA1 W10
[6] => AF
[COUNTRY] => GB
[7] => 123456
[PHONE] => 123456
[8] => 123456
[MOBILE] => 123456
[9] => 123456
[FAX] => 123456
[10] =>
[EMAIL] =>
[11] => £
[CURRENCY_SYMBOL] => £
[12] => GPB
[CURRENCY_CODE] => GPB
[13] => %d/%m/%Y
[DATE_FORMAT] => %d/%m/%Y
[14] => media/logo.png
[LOGO] => media/logo.png
[15] =>
[WWW] =>
[16] => 10
[OPENING_HOUR] => 10
[17] => 0
[OPENING_MINUTE] => 0
[18] => 17
[CLOSING_HOUR] => 17
[19] => 0
[CLOSING_MINUTE] => 0
[20] => 3.50
[TAX_RATE] => 3.50
[21] => <p>welcome</p>
[WELCOME_MSG] => <p>welcome</p>
[22] => <p>thanks</p>
[INVOICE_MSG] => <p>thanks</p>
)
- ADODB Manual - Link 1 - Returns array containing current row, or false if EOF. FetchRow( ) internally moves to the next record after returning the current row.
$rs->GetRowAssoc();
Array
(
[NAME] => QuantumWarp
[NUMBER] => 123456
[ADDRESS] => The Gurking
[CITY] => London
[STATE] => Greater London
[ZIP] => LA1 W10
[COUNTRY] => GB
[PHONE] => 123456
[MOBILE] => 123456
[FAX] => 123456
[EMAIL] =>
[CURRENCY_SYMBOL] => £
[CURRENCY_CODE] => GPB
[DATE_FORMAT] => %d/%m/%Y
[LOGO] => media/logo.png
[WWW] =>
[OPENING_HOUR] => 10
[OPENING_MINUTE] => 0
[CLOSING_HOUR] => 17
[CLOSING_MINUTE] => 0
[TAX_RATE] => 3.50
[WELCOME_MSG] => <p>welcome</p>
[INVOICE_MSG] => <p>thanks</p>
)
- ADODB Manual - Link 1 - Returns an associative array containing the current row. The keys to the array are the column names. The column names are upper-cased for easy access. To get the next row, you will still need to call MoveNext().
- Returns one row.
- same as $rs->GetRowAssoc($toUpper=true)
- you can use $rs->GetRowAssoc($toUpper=false) to give all lowercase
$rs->fields[$colname];
QuantumWarp
- ADODB Manual - Link 1 - Returns the value of the associated column $colname for the current row. The column name is case-insensitive.
- Returns one field.
- The 'f' is supposed to be lower case, it does not work otherwise.
Conclusion
Muliple Records/Rows = $rs->GetArray(); This returns a 2 dimensional array which allows you to loop through the records which are also arrays.
Single Record/Row = $rs->GetRowAssoc(); - This returns a standard associative array.
Single Item from a column in a single Row = $rs->Fields[$colname];
Links