function db_execute($sql, $params = array()) { $config = db_config(); $connection = db_connection($config); $st = $connection->prepare($sql); $params = db_params((array) $params); $st->execute((array) $params); return array($st, $connection); }
public static function hash($key_column, $value_column, $conditions = array(), $paging_params = false) { $colquote = db_params('column_quote_char'); $query = "SELECT {$colquote}" . $key_column . "{$colquote}, {$colquote}" . $value_column . "{$colquote} FROM " . get_called_class() . sql_where($conditions); if ($paging_params) { $query .= sql_orders_limits($paging_params); } return query_to_hash($query); }
function getdb($dsn = '', $user = '', $password = '') { static $config; if ($dsn == '') { extract($config); } else { $config = compact('dsn', 'user', 'password'); } static $db; if (!$db) { try { $db = new PDO($dsn, $user, $password); preg_match('/(.*):/', $dsn, $matches); // set database parameters based on dsn db_params('', $matches[1]); } catch (PDOException $e) { echo 'Connection failed: ' . $e->getMessage(); exit; } } return $db; }
function sql_order_str($col1 = '', $col1_order = '', $col2 = '', $col2_order = '', $col3 = '', $col3_order = '') { $colquote = db_params('column_quote_char'); if ($col1 == '') { return ''; } $col1_order = strtoupper($col1_order) == 'DESC' ? 'DESC' : ''; $col2_order = strtoupper($col2_order) == 'DESC' ? 'DESC' : ''; $col3_order = strtoupper($col3_order) == 'DESC' ? 'DESC' : ''; $order_str = " ORDER BY {$colquote}" . $col1 . "{$colquote} " . $col1_order; if ($col2 != "") { $order_str .= ", {$colquote}" . $col2 . "{$colquote} " . $col2_order; } if ($col3 != "") { $order_str .= ", {$colquote}" . $col3 . "{$colquote} " . $col3_order; } return $order_str . ' '; }
function update_records($table, $conditions, $newdata) { $newdata = array_escape($newdata); $column_quote_func = db_params('column_quote_func'); array_walk($newdata, $column_quote_func); if (count($newdata) > 0) { $query = "UPDATE " . $table . " SET " . implode(", ", $newdata) . sql_where($conditions); $result = sql_query_dbg($query); return sql_affected_rows($result); } return FALSE; }