123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257 |
- <?php
- require_once 'database.constants.inc.php';
- class Database {
-
-
- public static function get_main_database() {
- global $_configuration;
- return $_configuration['main_database'];
- }
-
- public static function get_statistic_database() {
- global $_configuration;
- return $_configuration['statistics_database'];
- }
-
- public static function get_scorm_database() {
- global $_configuration;
- return $_configuration['scorm_database'];
- }
-
- public static function get_user_personal_database() {
- global $_configuration;
- return $_configuration['user_personal_database'];
- }
-
- public static function get_current_course_database() {
- $course_info = api_get_course_info();
- if (empty($course_info['dbName'])) {
- return false;
- }
- return $course_info['dbName'];
- }
-
- public static function get_current_course_glued_database() {
- $course_info = api_get_course_info();
- if (empty($course_info['dbNameGlu'])) {
- return false;
- }
- return $course_info['dbNameGlu'];
- }
-
- public static function get_database_glue() {
- global $_configuration;
- return $_configuration['db_glue'];
- }
-
- public static function get_database_name_prefix() {
- global $_configuration;
- return $_configuration['db_prefix'];
- }
-
- public static function get_course_table_prefix() {
- global $_configuration;
- return $_configuration['table_prefix'];
- }
-
-
- public static function get_main_table($short_table_name) {
- return self::format_table_name(self::get_main_database(), $short_table_name);
- }
-
- public static function get_course_table($short_table_name, $database_name = '') {
- return self::format_glued_course_table_name(self::fix_database_parameter($database_name), $short_table_name);
- }
-
- public static function get_course_table_from_code($course_code, $table) {
- $course_table = self::get_main_table(TABLE_MAIN_COURSE);
- $course_cat_table = self::get_main_table(TABLE_MAIN_CATEGORY);
- $result = self::fetch_array(self::query(
- "SELECT $course_table.db_name, $course_cat_table.code
- FROM $course_table
- LEFT JOIN $course_cat_table
- ON $course_table.category_code = $course_cat_table.code
- WHERE $course_table.code = '$course_code'
- LIMIT 1"));
- return sprintf("%s.%s", $result[0], $table);
- }
-
- public static function get_statistic_table($short_table_name) {
- return self::format_table_name(self::get_statistic_database(), $short_table_name);
- }
-
- public static function get_scorm_table($short_table_name) {
- return self::format_table_name(self::get_scorm_database(), $short_table_name);
- }
-
- public static function get_user_personal_table($short_table_name) {
- return self::format_table_name(self::get_user_personal_database(), $short_table_name);
- }
- public static function get_course_chat_connected_table($database_name = '') {
- return self::format_glued_course_table_name(self::fix_database_parameter($database_name), CHAT_CONNECTED_TABLE);
- }
-
-
- public static function get_course_list() {
- $table = self::get_main_table(TABLE_MAIN_COURSE);
- return self::store_result(self::query("SELECT * FROM $table"));
- }
-
- public static function get_course_info($course_code) {
- $course_code = self::escape_string($course_code);
- $table = self::get_main_table(TABLE_MAIN_COURSE);
- $result = self::generate_abstract_course_field_names(
- self::fetch_array(self::query("SELECT * FROM $table WHERE `code` = '$course_code'")));
- return $result === false ? array('db_name' => '') : $result;
- }
-
- public static function get_user_info_from_id($user_id = '') {
- if (empty($user_id)) {
- return $GLOBALS['_user'];
- }
- $table = self::get_main_table(TABLE_MAIN_USER);
- $user_id = self::escape_string($user_id);
- return self::generate_abstract_user_field_names(
- self::fetch_array(self::query("SELECT * FROM $table WHERE user_id = '$user_id'")));
- }
-
- public static function get_course_by_category($category_id) {
- $info = self::fetch_array(self::query('SELECT course_code FROM '.self::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY).' WHERE id='.$category_id), 'ASSOC');
- return $info ? $info['course_code'] : false;
- }
-
- public static function generate_abstract_course_field_names($result_array) {
- $visual_code = isset($result_array['visual_code']) ? $result_array['visual_code'] : null;
- $code = isset($result_array['code']) ? $result_array['code'] : null;
- $title = isset($result_array['title']) ? $result_array['title'] : null;
- $db_name = isset($result_array['db_name']) ? $result_array['db_name'] : null;
- $category_code = isset($result_array['category_code']) ? $result_array['category_code'] : null;
- $result_array['official_code'] = $visual_code;
- $result_array['visual_code'] = $visual_code;
- $result_array['real_code'] = $code;
- $result_array['system_code'] = $code;
- $result_array['title'] = $title;
- $result_array['database'] = $db_name;
- $result_array['faculty'] = $category_code;
-
-
- return $result_array;
- }
-
- public static function generate_abstract_user_field_names($result_array) {
- $result_array['firstName'] = $result_array['firstname'];
- $result_array['lastName'] = $result_array['lastname'];
- $result_array['mail'] = $result_array['email'];
-
-
- return $result_array;
- }
-
- public static function count_rows($table) {
- $obj = self::fetch_object(self::query("SELECT COUNT(*) AS n FROM $table"));
- return $obj->n;
- }
-
-
- public static function affected_rows($connection = null) {
- global $database_connection;
- return $database_connection->affected_rows;
- }
-
- public static function close($connection = null) {
- return self::use_default_connection($connection) ? mysqli::close() : mysqli::close($connection);
- }
-
- public static function connect($parameters = array()) {
- global $database_connection;
-
- if (!isset($parameters['server'])) {
- $parameters['server'] = @ini_get('mysqli.default_host');
- if (empty($parameters['server'])) {
- $parameters['server'] = 'localhost:3306';
- }
- }
- if (!isset($parameters['username'])) {
- $parameters['username'] = @ini_get('mysqli.default_user');
- }
- if (!isset($parameters['password'])) {
- $parameters['password'] = @ini_get('mysqli.default_pw');
- }
- $database_connection = $parameters['persistent']
- ? new mysqli('p:'.$parameters['server'], $parameters['username'], $parameters['password'])
- : new mysqli($parameters['server'], $parameters['username'], $parameters['password']);
- if ($database_connection->connect_errno) {
- error_log($database_connection->connect_errno());
- return false;
- } else {
- return true;
- }
- }
-
- public static function errno($connection = null) {
- return self::use_default_connection($connection) ? mysqli::mysqli_errno() : mysqli::mysqli_errno($connection);
- }
-
- public static function error($connection = null) {
- return self::use_default_connection($connection) ? mysqli::mysqli_error() : mysqli::mysqli_error($connection);
- }
-
- public static function escape_string($string, $connection = null) {
- global $database_connection;
- return get_magic_quotes_gpc()
- ? ( $database_connection->escape_string(stripslashes($string)))
- : ( $database_connection->escape_string($string));
- }
-
- public static function fetch_array($result, $option = 'BOTH') {
- return ($option == 'ASSOC') ? $result->fetch_array(MYSQLI_ASSOC) : ($option == 'NUM' ? $result->fetch_array(MYSQLI_NUM) : $result->fetch_array());
- }
-
- public static function fetch_assoc($result) {
- return $result->fetch_assoc();
- }
-
- public static function fetch_object($result, $class = null, $params = null) {
- return !empty($class) ? (is_array($params) ? $result->fetch_object($class, $params) : $result->fetch_object($class)) : $result->fetch_object();
- }
-
- public static function fetch_row($result) {
- return $result->fetch_row();
- }
-
- public static function free_result($result) {
- return $result->free_result();
- }
-
- public function get_client_info() {
- return mysqli_get_client_info();
- }
-
- public static function get_databases($pattern = '', $connection = null) {
- $result = array();
- $query_result = Database::query(!empty($pattern) ? "SHOW DATABASES LIKE '".self::escape_string($pattern, $connection)."'" : "SHOW DATABASES", $connection);
- while ($row = Database::fetch_row($query_result)) {
- $result[] = $row[0];
- }
- return $result;
- }
-
- public static function get_fields($table, $pattern = '', $database = '', $including_properties = false, $connection = null) {
- $result = array();
- $query = "SHOW COLUMNS FROM `".self::escape_string($table, $connection)."`";
- if (!empty($database)) {
- $query .= " FROM `".self::escape_string($database, $connection)."`";
- }
- if (!empty($pattern)) {
- $query .= " LIKE '".self::escape_string($pattern, $connection)."'";
- }
- $query_result = Database::query($query, $connection);
- if ($including_properties) {
-
- while ($row = Database::fetch_row($query_result)) {
- $result[$row[0]] = $row;
- }
- } else {
-
- while ($row = Database::fetch_row($query_result)) {
- $result[] = $row[0];
- }
- }
- return $result;
- }
-
- public function get_host_info($connection = null) {
- return self::use_default_connection($connection) ? mysqli::mysqli_get_host_info() : mysqli::mysqli_get_host_info($connection);
- }
-
- public function get_proto_info($connection = null) {
- return self::use_default_connection($connection) ? mysqli::mysqli_get_proto_info() : mysqli::mysqli_get_proto_info($connection);
- }
-
- public function get_server_info($connection = null) {
- return self::use_default_connection($connection) ? mysqli::mysqli_get_server_info() : mysqli::mysqli_get_server_info($connection);
- }
-
- public static function get_tables($database = '', $pattern = '', $connection = null) {
- $result = array();
- $query = "SHOW TABLES";
- if (!empty($database)) {
- $query .= " FROM `".self::escape_string($database, $connection)."`";
- }
- if (!empty($pattern)) {
- $query .= " LIKE '".self::escape_string($pattern, $connection)."'";
- }
- $query_result = Database::query($query, $connection);
- while ($row = Database::fetch_row($query_result)) {
- $result[] = $row[0];
- }
- return $result;
- }
-
- public static function insert_id($connection = null) {
- global $database_connection;
- return $database_connection->insert_id;
- }
-
- public static function num_rows($result) {
- return is_a($result,'mysqli_result') ? $result->num_rows : false;
- }
-
- public static function result(&$resource, $row, $field = '') {
- if (self::num_rows($resource) > 0) {
- if (!empty($field)) {
- $r = mysqli_data_seek($resource, $row);
- return $r[$field];
- } else {
- return mysqli_data_seek($resource, $row);
- }
- } else { return null; }
- }
-
- public static function query($query, $connection = null, $file = null, $line = null) {
- global $database_connection;
- $result = @$database_connection->query($query);
- if ($database_connection->errno) {
- $backtrace = debug_backtrace();
- if (isset($backtrace[0])) {
- $caller = & $backtrace[0];
- } else {
- $caller = array();
- }
- if (isset($backtrace[1])) {
- $owner = & $backtrace[1];
- } else {
- $owner = array();
- }
- if (empty($file)) {
- $file = $caller['file'];
- }
- if (empty($line) && $line !== false) {
- $line = $caller['line'];
- }
- $type = $owner['type'];
- $function = $owner['function'];
- $class = $owner['class'];
- $server_type = api_get_setting('server_type');
- if (!empty($line) && !empty($server_type) && $server_type != 'production') {
- $info = '<pre>' .
- '<strong>DATABASE ERROR #'.self::errno($connection).':</strong><br /> ' .
- self::remove_XSS(self::error($connection)) . '<br />' .
- '<strong>QUERY :</strong><br /> ' .
- self::remove_XSS($query) . '<br />' .
- '<strong>FILE :</strong><br /> ' .
- (empty($file) ? ' unknown ' : $file) . '<br />' .
- '<strong>LINE :</strong><br /> ' .
- (empty($line) ? ' unknown ' : $line) . '<br />';
- if (empty($type)) {
- if (!empty($function)) {
- $info .= '<strong>FUNCTION :</strong><br /> ' . $function;
- }
- } else {
- if (!empty($class) && !empty($function)) {
- $info .= '<strong>CLASS :</strong><br /> ' . $class . '<br />';
- $info .= '<strong>METHOD :</strong><br /> ' . $function;
- }
- }
- $info .= '</pre>';
- echo $info;
- }
- }
- return $result;
- }
-
- public static function select_db($database_name, $connection = null) {
- global $database_connection;
- $database_connection->select_db($database_name);
- return !$database_connection->errno;
-
- }
-
- public static function store_result($result, $option = 'BOTH') {
- $array = array();
- if ($result !== false) {
- while ($row = self::fetch_array($result, $option)) {
- $array[] = $row;
- }
- }
- return $array;
- }
-
-
- public static function is_encoding_supported($encoding) {
- static $supported = array();
- if (!isset($supported[$encoding])) {
- $supported[$encoding] = false;
- if (strlen($db_encoding = self::to_db_encoding($encoding)) > 0) {
- if (self::num_rows(self::query("SHOW CHARACTER SET WHERE Charset = '".self::escape_string($db_encoding)."';")) > 0) {
- $supported[$encoding] = true;
- }
- }
- }
- return $supported[$encoding];
- }
-
- public static function make_charset_clause($encoding = null, $language = null) {
- if (empty($encoding)) {
- $encoding = api_get_system_encoding();
- }
- if (empty($language)) {
- $language = api_get_interface_language();
- }
- $charset_clause = '';
- if (self::is_encoding_supported($encoding)) {
- $db_encoding = Database::to_db_encoding($encoding);
- $charset_clause .= " DEFAULT CHARACTER SET `".$db_encoding."`";
- $db_collation = Database::to_db_collation($encoding, $language);
- if (!empty($db_collation)) {
- $charset_clause .= " DEFAULT COLLATE `".$db_collation."`";
- }
- }
- return $charset_clause;
- }
-
- public static function to_db_encoding($encoding) {
- static $result = array();
- if (!isset($result[$encoding])) {
- $result[$encoding] = null;
- $encoding_map = & self::get_db_encoding_map();
- foreach ($encoding_map as $key => $value) {
- if (api_equal_encodings($encoding, $key)) {
- $result[$encoding] = $value;
- break;
- }
- }
- }
- return $result[$encoding];
- }
-
- public static function from_db_encoding($db_encoding) {
- static $result = array();
- if (!isset($result[$db_encoding])) {
- $result[$db_encoding] = null;
- $encoding_map = & self::get_db_encoding_map();
- foreach ($encoding_map as $key => $value) {
- if (strtolower($db_encoding) == $value) {
- $result[$db_encoding] = $key;
- break;
- }
- }
- }
- return $result[$db_encoding];
- }
-
- public static function to_db_collation($encoding, $language = null) {
- static $result = array();
- if (!isset($result[$encoding][$language])) {
- $result[$encoding][$language] = null;
- if (self::is_encoding_supported($encoding)) {
- $db_encoding = self::to_db_encoding($encoding);
- if (!empty($language)) {
- $lang = api_purify_language_id($language);
- $res = self::check_db_collation($db_encoding, $lang);
- if (empty($res)) {
- $db_collation_map = & self::get_db_collation_map();
- if (isset($db_collation_map[$lang])) {
- $res = self::check_db_collation($db_encoding, $db_collation_map[$lang]);
- }
- }
- if (empty($res)) {
- $res = self::check_db_collation($db_encoding, null);
- }
- $result[$encoding][$language] = $res;
- } else {
- $result[$encoding][$language] = self::check_db_collation($db_encoding, null);
- }
- }
- }
- return $result[$encoding][$language];
- }
-
-
- private static function glue_course_database_name($database_name) {
- return self::get_course_table_prefix().$database_name.self::get_database_glue();
- }
-
- private static function fix_database_parameter($database_name) {
- if (empty($database_name)) {
- $course_info = api_get_course_info();
- return $course_info['dbNameGlu'];
- }
- return self::glue_course_database_name($database_name);
- }
-
- private static function format_glued_course_table_name($database_name_with_glue, $table) {
- return '`'.$database_name_with_glue.$table.'`';
- }
-
- private static function format_table_name($database, $table) {
- return '`'.$database.'`.`'.$table.'`';
- }
-
- private static function use_default_connection($connection) {
- return !is_resource($connection) && $connection !== false;
- }
-
- private static function remove_XSS(& $var) {
- return class_exists('Security') ? Security::remove_XSS($var) : @htmlspecialchars($var, ENT_QUOTES, api_get_system_encoding());
- }
-
- private static function & get_db_encoding_map() {
- static $encoding_map = array(
- 'ARMSCII-8' => 'armscii8',
- 'BIG5' => 'big5',
- 'BINARY' => 'binary',
- 'CP866' => 'cp866',
- 'EUC-JP' => 'ujis',
- 'EUC-KR' => 'euckr',
- 'GB2312' => 'gb2312',
- 'GBK' => 'gbk',
- 'ISO-8859-1' => 'latin1',
- 'ISO-8859-2' => 'latin2',
- 'ISO-8859-7' => 'greek',
- 'ISO-8859-8' => 'hebrew',
- 'ISO-8859-9' => 'latin5',
- 'ISO-8859-13' => 'latin7',
- 'ISO-8859-15' => 'latin1',
- 'KOI8-R' => 'koi8r',
- 'KOI8-U' => 'koi8u',
- 'SHIFT-JIS' => 'sjis',
- 'TIS-620' => 'tis620',
- 'US-ASCII' => 'ascii',
- 'UTF-8' => 'utf8',
- 'WINDOWS-1250' => 'cp1250',
- 'WINDOWS-1251' => 'cp1251',
- 'WINDOWS-1252' => 'latin1',
- 'WINDOWS-1256' => 'cp1256',
- 'WINDOWS-1257' => 'cp1257'
- );
- return $encoding_map;
- }
-
- private static function & get_db_collation_map() {
- static $db_collation_map = array(
- 'german' => 'german2',
- 'simpl_chinese' => 'chinese',
- 'trad_chinese' => 'chinese',
- 'turkce' => 'turkish'
- );
- return $db_collation_map;
- }
-
- private static function check_db_collation($db_encoding, $language) {
- if (empty($db_encoding)) {
- return null;
- }
- if (empty($language)) {
- $result = self::fetch_array(self::query("SHOW COLLATION WHERE Charset = '".self::escape_string($db_encoding)."' AND `Default` = 'Yes';"), 'NUM');
- return $result ? $result[0] : null;
- }
- $collation = $db_encoding.'_'.$language.'_ci';
- $query_result = self::query("SHOW COLLATION WHERE Charset = '".self::escape_string($db_encoding)."';");
- while ($result = self::fetch_array($query_result, 'NUM')) {
- if ($result[0] == $collation) {
- return $collation;
- }
- }
- return null;
- }
-
-
- public static function insert($table_name, $attributes) {
- if (empty($attributes) || empty($table_name)) {
- return false;
- }
- $filtred_attributes = array();
- foreach($attributes as $key => $value) {
- $filtred_attributes[$key] = "'".self::escape_string($value)."'";
- }
- $params = array_keys($filtred_attributes);
- $values = array_values($filtred_attributes);
- if (!empty($params) && !empty($values)) {
- $sql = 'INSERT INTO '.$table_name.' ('.implode(',',$params).') VALUES ('.implode(',',$values).')';
- $result = self::query($sql);
- return self::get_last_insert_id();
- }
- return false;
- }
-
- public static function select($columns = '*' , $table_name, $conditions = array(), $type_result = 'all', $option = 'ASSOC') {
- $conditions = self::parse_conditions($conditions);
-
- $clean_columns = '';
- if (is_array($columns)) {
- $clean_columns = implode(',', $columns);
- } else {
- if ($columns == '*') {
- $clean_columns = '*';
- } else {
- $clean_columns = (string)$columns;
- }
- }
- $sql = "SELECT $clean_columns FROM $table_name $conditions";
- $result = self::query($sql);
- $array = array();
-
- if ($type_result == 'all') {
- while ($row = self::fetch_array($result, $option)) {
- if (isset($row['id'])) {
- $array[$row['id']] = $row;
- } else {
- $array[] = $row;
- }
- }
- } else {
- $array = self::fetch_array($result, $option);
- }
- return $array;
- }
-
- private function parse_conditions($conditions) {
- if (empty($conditions)) {
- return '';
- }
- $return_value = '';
- foreach ($conditions as $type_condition => $condition_data) {
- $type_condition = strtolower($type_condition);
- switch($type_condition) {
- case 'where':
- foreach ($condition_data as $condition => $value_array) {
- if (is_array($value_array)) {
- $clean_values = array();
- foreach($value_array as $item) {
- $item = Database::escape_string($item);
- $clean_values[]= "'$item'";
- }
- } else {
- $value_array = Database::escape_string($value_array);
- $clean_values = "'$value_array'";
- }
- if (!empty($condition) && !empty($clean_values)) {
- $condition = str_replace('?','%s', $condition);
- $condition = vsprintf($condition, $clean_values);
- $where_return .= $condition;
- }
- }
- if (!empty($where_return)) {
- $return_value = " WHERE $where_return" ;
- }
- break;
- case 'order':
- $order_array = explode(' ', $condition_data);
- if (!empty($order_array)) {
- if (count($order_array) > 1) {
- $order_array[0] = self::escape_string($order_array[0]);
- if (!empty($order_array[1])) {
- $order_array[1] = strtolower($order_array[1]);
- $order = 'desc';
- if (in_array($order_array[1], array('desc', 'asc'))) {
- $order = $order_array[1];
- }
- }
- $return_value .= ' ORDER BY '.$order_array[0].' '.$order;
- } else {
- $return_value .= ' ORDER BY '.$order_array[0].' DESC ';
- }
- }
- break;
- case 'limit':
- $limit_array = explode(',', $condition_data);
- if (!empty($limit_array)) {
- if (count($limit_array) > 1) {
- $return_value .= ' LIMIT '.intval($limit_array[0]).' , '.intval($limit_array[1]);
- } else {
- $return_value .= ' LIMIT '.intval($limit_array[0]);
- }
- }
- break;
- }
- }
- return $return_value;
- }
- private function parse_where_conditions($coditions){
- return self::parse_conditions(array('where'=>$coditions));
- }
-
- public static function delete($table_name, $where_conditions) {
- $result = false;
- $where_return = self::parse_where_conditions($where_conditions);
- $sql = "DELETE FROM $table_name $where_return ";
- $result = self::query($sql);
- $affected_rows = self::affected_rows();
-
- return $affected_rows;
- }
-
- public static function update($table_name, $attributes, $where_conditions = array()) {
- if (!empty($table_name) && !empty($attributes)) {
- $update_sql = '';
-
- $count = 1;
- foreach ($attributes as $key=>$value) {
- $value = self::escape_string($value);
- $update_sql .= "$key = '$value' ";
- if ($count < count($attributes)) {
- $update_sql.=', ';
- }
- $count++;
- }
- if (!empty($update_sql)) {
-
- $where_return = self::parse_where_conditions($where_conditions);
- $sql = "UPDATE $table_name SET $update_sql $where_return ";
-
- $result = self::query($sql);
- $affected_rows = self::affected_rows();
- return $affected_rows;
- }
- }
- return false;
- }
-
-
- public static function get_language_isocode($language) {
- return api_get_language_isocode($language);
- }
-
- public static function get_last_insert_id() {
- global $database_connection;
- return $database_connection->insert_id($database_connection);
- }
- }
|