"; } return $arr_result; } //Performs an sql action (INSERT,UPDATE,DELETE) //Returns true if action succeeds //Returns the generated id if action succeeds if $return_id is true function db_action($query, $return_id=false, $db = 'emwealth',$forupdate='0') { // connect to database if($db == 'emwealth_070408') { $conn = db_connect('c'); } else { $conn = db_connect('a'); } if (!$conn) // database connection error" return 0; $res = mysql_query($query, $conn); //echo mysql_error($conn); if(mysql_error($conn)){ return 0; } if($return_id && $res) { $res = mysql_insert_id($conn); } if($forupdate==1){ $res=1; } db_disconnect($conn); return $res; } //Performs an sql query (SELECT) //$mode : M = multiple rows (default) // S = single row function db_query($query,$mode='M',$db='emwealth') { // connect to database if($db == 'emwealth_070408') { $conn = db_connect('c'); } else { $conn = db_connect('b'); } if (!$conn) // database connection error" return 0; // check if the user and password is valid $result = mysql_query($query, $conn); if (!$result || mysql_num_rows($result) == 0) { return 0; } db_disconnect($conn); return ($mode == 'S') ? mysql_fetch_array($result) : db_array($result); } //Returns a MySQL query in a XML 1.0 document function db_query_xml($query,$db='emweath') { // connect to database if($db == 'phs5') { $conn = db_connect('c'); } else { $conn = db_connect('b'); } if (!$conn) // database connection error" return 0; $res = mysql_query($query, $conn); db_disconnect($conn); // Create XML document $xml = domxml_new_doc('1.0'); // add root node $root = $xml->create_element('root'); $root = $xml->append_child($root); if($res) { // process all rows of the table while($row = mysql_fetch_assoc($res)) { // add node for each record $element = $xml->create_element('element'); $element = $root->append_child($element); // add a child node for each field foreach ($row as $fieldname => $fieldvalue) { $child = $xml->create_element($fieldname); $child = $element->append_child($child); $value = mb_convert_encoding($value,'utf-8','utf-8'); $value = $xml->create_text_node($fieldvalue); $value = $child->append_child($value); } } } return $xml->dump_mem(true, 'utf-8'); } function db_account_query($sql_query, $mode='M') { $query = "SELECT userpercentagesetting FROM sys_parameter"; $res = db_query($query,'S'); if($res[0] == 0) //Query from emweath db { return db_query($sql_query, $mode); } else //Query from phs5 db { $sql_query = str_replace("account_cll", "account", $sql_query); return db_query($sql_query, $mode, 'phs5'); } } function db_account_action($sql_query) { $query = "SELECT userpercentagesetting FROM sys_parameter"; $res = db_query($query,'S'); if($res[0] == 0) //Perform action on emweath db { return db_action($sql_query, false); } else //Perform action on phs5 db { $sql_query = str_replace("account_cll", "account", $sql_query); return db_action($sql_query, false, 'phs5'); } } /* TRANSACTION STUFF */ //For TRANSACTION purposes, does not disconnect. function db_tran_start() { //Connect for writing $conn = db_connect("a"); if (!$conn) // database connection error" return 0; mysql_query("BEGIN", $conn); return $conn; } //$commit -> true to commit, false to rollback function db_tran_end($conn, $commit = true) { if($commit) { mysql_query("COMMIT", $conn); } else { mysql_query("ROLLBACK", $conn); } //db_disconnect($conn); } function db_tran_action($query, $conn, $return_id=false,$forupdate='0') { $res = mysql_query($query, $conn); if($return_id && $res) { $res = mysql_insert_id(); } if($forupdate==1){ if(!mysql_error()){ return 2; } } return $res; } function db_tran_query($query, $conn, $mode='M') { $result = mysql_query($query, $conn); if (!$result || mysql_num_rows($result) == 0) { return 0; } return ($mode == 'S') ? mysql_fetch_array($result) : db_array($result); } /* Added to start cater session */ # kira - 090608 if(session_id() == ""){ session_start(); } ?>