Class DataBaseConnector

Description

Encapsulates databse functions.

This class encapsulates all of the functions for connecting to the database.

  • author: Richard Sharp
  • copyright: 2011

Located in /DataBaseConnector.class.php (line 10)

 
	
			
Variable Summary
string $DatabaseName
string $Host
string $LastQuery
string $LogFile
string $Password
string $Username
Method Summary
void __construct ([string $Username = ""], [string $Password = ""], [string $DatabaseName = ""], [string $Host = ""])
void __destruct ()
string Escape (string $Value)
string GetLastError ()
int Insert (string $Table, array $Fields)
mixed Query (string $Query)
bool Replace (string $Table, array $Fields, [boolean $Delayed = false])
mixed Select (string $Query)
bool TestConnection ()
bool Update (string $Table, array $Fields, string $Condition, [int $Limit = 0])
Variables
string $DatabaseName = "" (line 33)

Gets or sets the database name.

  • access: public
string $Host = "localhost" (line 39)

Gets or sets the database host. Default is localhost.

  • access: public
string $LastQuery = "" (line 45)

Gets the raw text of the last query performed.

  • access: public
string $LogFile = "" (line 51)

If set, an error log will be written to this file. Use a full file path.

  • access: public
string $Password = "" (line 57)

Gets or sets the database password.

  • access: public
boolean $UpdateTimestamps = true (line 27)

Gets or sets whether or not to automaticllay update the Modified and Created fields in the table (must be those exact names).

  • access: public
string $Username = "" (line 63)

Gets or sets the database username.

  • access: public
Methods
Constructor __construct (line 83)

Constructor for the class.

void __construct ([string $Username = ""], [string $Password = ""], [string $DatabaseName = ""], [string $Host = ""])
  • string $Username: The database username.
  • string $Password: The database password.
  • string $DatabaseName: The database name.
  • string $Host: The database host.
Destructor __destruct (line 96)

Destructor for the class.

void __destruct ()
Escape (line 144)

Escapes the value to be placed in a field. This helps prevent problems with quotes, and mitigates SQL injection attacks.

  • access: public
string Escape (string $Value)
  • string $Value: The value to escape.
GetAffectedRows (line 157)

Returns the number of rows affected by the previous query

  • access: public
int GetAffectedRows ()
GetLastError (line 167)

Gets the text of the last error, if any.

  • access: public
string GetLastError ()
Insert (line 179)

Inserts a record into the database. Returns the insert auto-incremented ID on success, false on failure. Unless UpdateTimestamps is set to false, fields will automatically be added for Modified and Created.

  • access: public
int Insert (string $Table, array $Fields)
  • string $Table: The name of the table.
  • array $Fields: An array of the fields/values to insert. Each element key is the column name for the table, and the value is the value to insert.
Query (line 217)

Runs a raw query on the database that does not expect any return. Returns the result of that query, which may be a boolean for failure or an object for success of some queries.

  • access: public
mixed Query (string $Query)
  • string $Query: The query to run.
Replace (line 244)

Performs an Update query on the database. Returns true on success, false on failure.

  • access: public
bool Replace (string $Table, array $Fields, [boolean $Delayed = false])
  • string $Table: The name of the table.
  • array $Fields: An associative array of the fields to update. Each element's key is the column name in the table, and the value of the element is the value to update.
  • boolean $Delayed: Whether or not to use delayed replace. Default false.
Select (line 282)

Runs a Select query on the database. Returns an associative array of rows on success, false on failure. This will also loop through all of the results and clean the data (stripslashes).

  • access: public
mixed Select (string $Query)
  • string $Query: The query to run.
TestConnection (line 311)

Tests to make sure the connection to the database is open, and if not, attempts to re-open the connection.

  • access: public
bool TestConnection ()
Update (line 337)

Performs an Update query on the database. Returns success or failure.

  • access: public
bool Update (string $Table, array $Fields, string $Condition, [int $Limit = 0])
  • string $Table: The name of the table.
  • array $Fields: An associative array of the fields to update. Each element's key is the column name in the table, and the value of the element is the value to update.
  • string $Condition: The WHERE clause of the query.
  • int $Limit: Optional. The limit to the number of rows that should be affected.

Documentation generated on Wed, 26 Jan 2011 15:24:43 -0700 by phpDocumentor 1.4.3