This is an old revision of the document!
Table of Contents
Database API
- As soon as you include the database handler in the front controller the database connection is made and the resource will be assigned to $global['db'] variable.
required_once($global['approot'].'inc/handler_db.inc');
Using $global['db']
- People who want to make database calls can use the $global['db'] connection variable.
function shn_ws_mpr_insert_person($full_name, $family_name, $l10n_name, $custom_name) { global $global; global $ws_error_msg; $sql = "INSERT INTO person_uuid ( full_name, family_name, l10n_name, custom_name) "; $sql .= "VALUES ( '$full_name', '$family_name', '$l10n_name', '$custom_name')"; if(! $global['db']->Execute($sql) ) return new soap_fault('Client', '', 'Could not insert $full_name'); else return 'Success fully inserted $full_name'; }
Using shn_db_clean
- You can use shn_db_clean($string) to clean and put escape characters to the user input data. This will prevent SQL Injecttions. NOTE: make sure you don't use this on an already escaped string.
... $full_name = shn_db_clean($_POST['fullname']); $sql = "INSERT INTO person_uuid ( full_name ) VALUE ('$full_name'); ...
Using shn_db_insert_phonetic
- You may use shn_db_insert_phonetic($name,$pgl_uuid) if you would like to have a soundex and metaphone search for the given word.
... $full_name = $_POST['fullname']; $p_uuid = '12'; shn_db_insert_phonetic($full_name,$p_uuid); ...
Using shn_db_insert
- You may use shn_db_insert() if you have a populated an associative array with 'field name' ⇒ 'value' .
... $person_uuid['full_name'] = $_POST['fullname']; $person_uuid['last_name'] = $_POST['lname']; $person_uuid['l10n_name'] = $_POST['l10nname']; $person_uuid['custom_name'] = $_POST['custname']; shn_db_insert($person_uuid,'person_uuid'); ...
Using shn_db_update
- You may use shn_db_update() if you have a populated an associative array with 'field name' ⇒ 'value' and that you like to updated the record.
... $person_uuid['full_name'] = $_POST['fullname']; $person_uuid['last_name'] = $_POST['lname']; $person_uuid['l10n_name'] = $_POST['l10nname']; $person_uuid['custom_name'] = $_POST['custname']; shn_db_update($person_uuid,'person_uuid'," WHERE p_uuid = '12'"); ...
Reference
- We are using PHP ADOdb Library (And they have an excellent documentation ).
-
- Commonly used APIs