mirror of
https://github.com/jimeh/litemysql.git
synced 2026-02-19 04:46:39 +00:00
bumbed version to 1.0.2: fixed an issue with using multiple tables, fixed the limit issue of find(), update(), and delete() functions, and made load_settings() capable of taking a filename, or an array with settings as input
This commit is contained in:
@@ -1,3 +1,29 @@
|
||||
LiteMySQL 1.0.2
|
||||
-----------------------------------
|
||||
Date: 16-Dec-2007
|
||||
|
||||
- Fixed an issue which made using the same
|
||||
instance of LiteMySQL not play very nice
|
||||
at all when used with multiple tables.
|
||||
use the select_table() function to
|
||||
select and/or change the current table.
|
||||
|
||||
- find(), update(), and delete() functions
|
||||
default to only effect one row (LIMIT 1).
|
||||
This should be configurable with the
|
||||
options parameter, but thanks to some
|
||||
stupid code on my behalf, it was simply
|
||||
overridden if it was set manually.
|
||||
|
||||
- load_settings() function can now take a
|
||||
filename with a configuration array, or
|
||||
an array with the settings directly as
|
||||
input. Rather than only being able to
|
||||
load settings from a file.
|
||||
|
||||
-----------------------------------
|
||||
|
||||
|
||||
LiteMySQL 1.0.1
|
||||
-----------------------------------
|
||||
Date: 14-Dec-2007
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
/*
|
||||
|
||||
Class: LiteMySQL v1.0.1
|
||||
Class: LiteMySQL v1.0.2
|
||||
http://code.google.com/p/litemysql/
|
||||
|
||||
Simple & easy to use class to automate the repetative & boring stuff.
|
||||
@@ -180,7 +180,7 @@ class LiteMySQL {
|
||||
if ( $this->connect() ) {
|
||||
// set or override database and table settings
|
||||
if ( !empty($args[3]) ) $this->select_db($args[3]);
|
||||
if ( !empty($args[4]) ) $this->table = $args[4];
|
||||
if ( !empty($args[4]) ) $this->select_table($args[4]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -219,7 +219,7 @@ class LiteMySQL {
|
||||
if ( $username !== null ) $this->username = $username;
|
||||
if ( $password !== null ) $this->password = $password;
|
||||
if ( $database !== null ) $this->database = $database;
|
||||
if ( $table !== null ) $this->table = $table;
|
||||
// if ( $table !== null ) $this->table = $table;
|
||||
|
||||
if ( $this->host !== null ) {
|
||||
|
||||
@@ -233,9 +233,8 @@ class LiteMySQL {
|
||||
$this->resource = call_user_func_array($connect_function, array($this->host, $this->username, $this->password));
|
||||
if ( $this->resource !== false ) {
|
||||
$this->connected = true;
|
||||
if ( $this->database !== null ) {
|
||||
$this->select_db($this->database);
|
||||
}
|
||||
if ( $this->database !== null ) $this->select_db($this->database);
|
||||
if ( $table !== null ) $this->select_table($table);
|
||||
self::$resources[$this->connection_id] = &$this->resource;
|
||||
return true;
|
||||
}
|
||||
@@ -243,9 +242,8 @@ class LiteMySQL {
|
||||
$this->resource = &self::$resources[$this->connection_id];
|
||||
if ( $this->resource !== false ) {
|
||||
$this->connected = true;
|
||||
if ( $this->database !== null ) {
|
||||
$this->select_db($this->database);
|
||||
}
|
||||
if ( $this->database !== null ) $this->select_db($this->database);
|
||||
if ( $table !== null ) { $this->select_table($table);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -279,23 +277,32 @@ class LiteMySQL {
|
||||
*/
|
||||
function select_table ($table = null) {
|
||||
if ( $table !== null ) $this->table = $table;
|
||||
if ( $this->columns !== null ) {
|
||||
$this->columns = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load settings from file
|
||||
* @param file the php file containing an array
|
||||
* @param variable the variable name to load the array from
|
||||
* @param input filename of config file, or an array with settings
|
||||
* @param variable the variable name to load the array from when loading a config file
|
||||
* @return true or false
|
||||
*/
|
||||
function load_settings ($file = null, $variable = null) {
|
||||
if ( $file !== null && is_file($file) ) {
|
||||
function load_settings ($input = null, $variable = null) {
|
||||
if ( is_array($input) && count($input) ) {
|
||||
$properties = array('host', 'username', 'password', 'database', 'table', 'persistent');
|
||||
foreach( $properties as $value ) {
|
||||
if ( array_key_exists($value, $input) && $input[$value] != '' ) $this->$value = $input[$value];
|
||||
}
|
||||
return true;
|
||||
} elseif ( is_string($input) && $input !== null && is_file($input) ) {
|
||||
if ( $variable === null ) $variable = $this->config_var;
|
||||
|
||||
include($file);
|
||||
include($input);
|
||||
$settings = &$$variable;
|
||||
|
||||
$properties = array('host', 'username', 'password', 'database', 'table', 'persistent');
|
||||
|
||||
foreach( $properties as $value ) {
|
||||
if ( array_key_exists($value, $settings) ) $this->$value = $settings[$value];
|
||||
}
|
||||
@@ -318,7 +325,9 @@ class LiteMySQL {
|
||||
* @return array with result row or false
|
||||
*/
|
||||
function find ($conditions = null, $options = array()) {
|
||||
$options['limit'] = 1;
|
||||
if ( !array_key_exists('limit', $options) ) {
|
||||
$options['limit'] = 1;
|
||||
}
|
||||
$sql = $this->build_find_query($conditions, $options);
|
||||
$result = $this->query($sql);
|
||||
if ( $row = mysql_fetch_assoc($result) ) {
|
||||
@@ -379,7 +388,9 @@ class LiteMySQL {
|
||||
* @return true or false
|
||||
*/
|
||||
function update ($conditions = null, $input = array(), $options = array()) {
|
||||
$options['limit'] = 1;
|
||||
if ( !array_key_exists('limit', $options) ) {
|
||||
$options['limit'] = 1;
|
||||
}
|
||||
return $this->update_all($conditions, $input, $options);
|
||||
}
|
||||
|
||||
@@ -402,7 +413,9 @@ class LiteMySQL {
|
||||
* @return true or false
|
||||
*/
|
||||
function delete ($conditions = null, $options = array()) {
|
||||
$options['limit'] = 1;
|
||||
if ( !array_key_exists('limit', $options) ) {
|
||||
$options['limit'] = 1;
|
||||
}
|
||||
return $this->delete_all($conditions, $options);
|
||||
}
|
||||
|
||||
@@ -743,6 +756,7 @@ class LiteMySQL {
|
||||
*/
|
||||
function get_columns () {
|
||||
if ( $this->connected && $this->selected_database != null && $this->table != null ) {
|
||||
$this->columns = null;
|
||||
$sql = 'SHOW COLUMNS FROM `'.$this->table.'`;';
|
||||
$result = $this->query($sql);
|
||||
if ( mysql_num_rows($result) > 0 ) {
|
||||
|
||||
Reference in New Issue
Block a user