Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * OrestesFW Database Class
- *
- * Completely envisioned by Ian Macalinao
- *
- * @package OrestesFW
- * @subpackage Database
- * @since 0.1
- */
- if (!ORESTES) { die("Access Denied."); } //Checks to see if this file is included
- /**
- * OrestesFW Database Access Object
- *
- * @package OrestesFW
- * @subpackage Database
- * @since 0.1
- */
- class orestes_db {
- /**
- * OrestesFW Table Prefix
- *
- * Just in case you have multiple installs of Orestes within the same database.
- *
- * @since 0.1
- * @access private
- * @var string
- */
- var $prefix;
- /**
- * Connects to the database server and selects a database.
- *
- * PHP4 compatibility layer for calling the PHP5 constructor.
- *
- * @uses orestes_db::__construct() Passes parameters and returns result
- * @since 0.1
- *
- * @param string $db_host MySQL Database Host
- * @param string $db_user MySQL Database User
- * @param string $db_pass MySQL Database Password
- * @param string $db_name MySQL Database Name
- */
- function ordb($db_host, $db_user, $db_pass, $db_name) {
- return $this->__construct($db_host, $db_user, $db_pass, $db_name);
- }
- /**
- * Connects to the database server and selects a database.
- *
- * PHP5 style constructor for compatibility with PHP5. Sets
- * up the actual connection.
- *
- * @since 0.1
- *
- * @param string $db_host MySQL Database Host
- * @param string $db_user MySQL Database User
- * @param string $db_pass MySQL Database Password
- * @param string $db_name MySQL Database Name
- */
- function __construct($db_host, $db_user, $db_pass, $db_name) {
- global $db_prefix;
- $link = mysql_connect($db_host, $db_user, $db_pass);
- $db = mysql_select_db($db_name);
- $this->prefix = $db_prefix;
- return $link;
- }
- /**
- * Perform a MySQL database query using the current database connection
- *
- * Derived from PHP-Fusion.
- *
- * @since 0.1
- *
- * @param string $query Database query
- * @return resource|false Returns the resource of the query or a false value if the query fails.
- */
- function query($query) {
- $result = @mysql_query($query);
- if (!$result) {
- echo mysql_error();
- return false;
- } else {
- return $result;
- }
- }
- /**
- * Counts the number of rows matching the selected conditions
- *
- * Derived from PHP-Fusion.
- *
- * @since 0.1
- *
- * @param string $field The field you wish to count, usually parenthesized.
- * @param string $table The table which the field is located in.
- * @param string $conditions Optional. Conditions in the form of SQL query "x='y' AND y='x'".
- * @return int|false Number of rows fulfilling the conditions, or if none, false
- */
- function count($field,$table,$conditions="") {
- $cond = ($conditions ? " WHERE ".$conditions : "");
- $result = @mysql_query("SELECT Count".$field." FROM ".DB_PREFIX.$table.$cond);
- if (!$result) {
- echo mysql_error();
- return false;
- } else {
- $rows = mysql_result($result, 0);
- return $rows;
- }
- }
- /**
- * Performs mysql_result without errors.
- *
- * Derived from PHP-Fusion.
- *
- * @since 0.1
- *
- * @param resource $query MySQL Resource
- * @param int $row Row number to select.
- * @return mixed|false Cell data
- */
- function result($query, $row) {
- $result = @mysql_result($query, $row);
- if (!$result) {
- echo mysql_error();
- return false;
- } else {
- return $result;
- }
- }
- /**
- * Returns the number of rows in a result set.
- *
- * Derived from PHP-Fusion.
- *
- * @since 0.1
- *
- * @param resource $query MySQL Resource
- * @return int|false Number of rows that the query returns
- */
- function rows($query) {
- $result = @mysql_num_rows($query);
- return $result;
- }
- /**
- * Creates an associative array based on a MySQL Resource
- *
- * Derived from PHP-Fusion.
- *
- * @since 0.1
- *
- * @param resource $query MySQL Resource
- * @return array Associative array of query.
- */
- function makearray($query) {
- $result = @mysql_fetch_assoc($query);
- if (!$result) {
- echo mysql_error();
- return false;
- } else {
- return $result;
- }
- }
- /**
- * Gets a specific row from a table in an associative array.
- *
- * @since 0.1
- *
- * @param string $query Database query
- * @return array The row's contents.
- */
- function get_row($query) {
- return $this->makearray($this->query($query));
- }
- /**
- * Returns an array of multiple rows that match a single query
- *
- * @param <type> $query
- * @return <type> Multi-dimensional array of rows sort
- */
- function results($query) {
- $result = $this->query($query);
- $i = 0;
- while ($row = $this->makearray($result)) {
- $results[$i] = $row;
- $i++;
- }
- return $results;
- }
- function arraynum($query) {
- $result = @mysql_fetch_row($query);
- if (!$result) {
- echo mysql_error();
- return false;
- } else {
- return $result;
- }
- }
- /**
- * Retrieves a single database cell's contents in the current connection.
- *
- * Chooses the first result found, if multiple
- * cells fulfill the condition. (I'm Feeling Lucky)
- *
- * @since 0.1
- *
- * @param string $query Database query
- * @return mixed|false Cell data
- */
- function get_var($query) {
- $result = $this->query($query);
- return $this->result($result, 0);
- }
- }
- //Connect to the database and initialize the orestes_db object
- $o_d = new orestes_db($db_host, $db_user, $db_pass, $db_name);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement