LEPTON CMS 7.0.0
feel free to keep it strictly simple...
Loading...
Searching...
No Matches
LEPTON_database Class Reference

Public Member Functions

 __construct (array &$settings=[])
 
 __destruct ()
 
 get_error ()
 
 is_error ()
 
 get_db_handle ()
 
 get_db_key ()
 
 connect (array &$settings=[])
 
 simple_query (string $sMySQL_Query="", array $aParams=[])
 
 get_one (string $SQL)
 
 list_tables (string $strip="")
 
 describe_table (string $sTableName, array &$aStorage=[], int $iForm=self::DESCRIBE_RAW)
 
 execute_query (string $aQuery="", bool $bFetch=false, array &$aStorage=[], bool $bFetchAll=true)
 
 build_and_execute (string $type, string $table_name, array $table_values, string $condition="", string $key="")
 
 __call (string $sNameParam, array $aParams)
 
 query (string $sSqlQuery="")
 
 add_column (string $table='', string $column='', string $desc='')
 

Static Public Member Functions

static getInstance (array &$settings=[])
 
static __callStatic (string $method, array $args)
 

Data Fields

const DESCRIBE_RAW = 0
 
const DESCRIBE_ASSOC = 1
 
const DESCRIBE_ONLY_NAMES = 2
 
bool $bHaltOnError = true
 
bool $bForceDieOnError = true
 

Protected Member Functions

 set_error (string $error='')
 

Detailed Description

This file is part of LEPTON Core, released under the GNU GPL Please see LICENSE and COPYING files in your package for details, specially for terms and warranties.

NOTICE:LEPTON CMS Package has several different licenses. Please see the individual license in the header of each single file or info.php of modules and templates.

Author
LEPTON Project
Examples
C:/Develope/SVN/upload/framework/classes/lepton_database.php.

Definition at line 24 of file lepton_database.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( array &  $settings = [])

Constructor of the class database

Parameters
array$settingsAssoc. array with the connection-settings. Call by reference!

@seealso Method "connect" for details.

Examples
C:/Develope/SVN/upload/framework/classes/lepton_database.php.

Definition at line 96 of file lepton_database.php.

◆ __destruct()

__destruct ( )

Destructor of the class database

Examples
C:/Develope/SVN/upload/framework/classes/lepton_database.php.

Definition at line 104 of file lepton_database.php.

Member Function Documentation

◆ __call()

__call ( string  $sNameParam,
array  $aParams 
)

Method is called when a requested method in this class does not exists.

see: https://www.php.net/manual/de/language.oop5.overloading.php#object.call

Parameters
string$sNameParam
array$aParams
Examples
C:/Develope/SVN/upload/framework/classes/lepton_database.php.

Definition at line 735 of file lepton_database.php.

◆ __callStatic()

static __callStatic ( string  $method,
array  $args 
)
static

Method is called when a requested static method in this class does not exists.

see: https://www.php.net/manual/de/language.oop5.overloading.php#object.call

Parameters
string$method
array$args
Examples
C:/Develope/SVN/upload/framework/classes/lepton_database.php.

Definition at line 762 of file lepton_database.php.

◆ add_column()

add_column ( string  $table = '',
string  $column = '',
string  $desc = '' 
)

Add column to existing table

Parameters
string$tableThe table name to be extended.
string$columnName
string$desccolumn type and default
Returns
bool true.
LEPTON_database::getInstance()->add_column('news','new_name','varchar(64) NOT NULL DEFAULT "0"');
static getInstance(array &$settings=[])
Examples
C:/Develope/SVN/upload/framework/classes/lepton_database.php.

Definition at line 816 of file lepton_database.php.

◆ build_and_execute()

build_and_execute ( string  $type,
string  $table_name,
array  $table_values,
string  $condition = "",
string  $key = "" 
)

Public function to build and execute a mySQL query direct. Use this function/method for update and insert values only. As for a simple select you can use "prepare_and_execute" above.

Parameters
string$typeA "job"-type: this time only "update" and "insert" are supported.
string$table_nameA valid table-name (incl. table-prefix).
array$table_valuesAn array within the table-field-names and values.
string$conditionAn optional condition for "update" - this time a simple string.
string$keyAn optional "no update" key field to be excluded on update while "insert_on_duplicate_key_update" - a simple string containing 1 key field.
Returns
int If success number of affected rows.
Examples
C:/Develope/SVN/upload/framework/classes/lepton_database.php.

Definition at line 633 of file lepton_database.php.

◆ connect()

connect ( array &  $settings = [])
final

Establish the connection to the desired database defined in /config.php.

This function does not connect multiple times, if the connection is already established the existing database handle will be used.

Parameters
array$settingsAssoc. array within optional settings. Pass by reference!
Returns
void

@notice Param 'settings' is an assoc. array with the connection-settings, e.g.: $settings = array( 'host' => "example.tld", 'user' => "example_user_string", 'pass' => "example_user_password", 'name' => "example_database_name", 'port' => "1003", 'key' => "a unique key", // optional 'cipher' => "aes-256-cbc", // optional 'iv' => "12_%#0123773345_", // MUST be match to the given 'cipher'! 'ivlen' => 16, // MUST be set if 'iv' has a different length than 16! 'charset' => "utf8" );

KEEP in mind, that the optional keys are set in the lepton.ini.php! So if you try to use the secure_* methods on a new connection via the $settings there can be causes some unintended results if these keys are missing or formatted!

To set up the connection to another charset as 'utf8' you can also define another one inside the config.php e.g. define('DB_CHARSET', 'utf8');

Any System-constants?

Try to set the charset.

Since 4.0 there could be also a setting for the MYSQL-Mode in the lepton.ini.

See also
https://dev.mysql.com/doc/refman/5.7/en/sql-mode.html#sql-mode-important
Examples
C:/Develope/SVN/upload/framework/classes/lepton_database.php.

Definition at line 191 of file lepton_database.php.

◆ describe_table()

describe_table ( string  $sTableName,
array &  $aStorage = [],
int  $iForm = self::DESCRIBE_RAW 
)

Placed for all fields from a given table(-name) an assoc. array inside a given storage-array.

Parameters
string$sTableNameA valid table-name.
array$aStorageAn array to store the results. Call by reference!
Returns
bool True if success, otherwise false.
Examples
C:/Develope/SVN/upload/framework/classes/lepton_database.php.

Definition at line 528 of file lepton_database.php.

◆ execute_query()

execute_query ( string  $aQuery = "",
bool  $bFetch = false,
array &  $aStorage = [],
bool  $bFetchAll = true 
)

◆ get_db_handle()

get_db_handle ( )

Get the MySQL DB handle

Returns
resource or boolean false if no connection is established
Examples
C:/Develope/SVN/upload/framework/classes/lepton_database.php.

Definition at line 144 of file lepton_database.php.

◆ get_db_key()

get_db_key ( )

Get the internal DB key

Returns
string
Examples
C:/Develope/SVN/upload/framework/classes/lepton_database.php.

Definition at line 154 of file lepton_database.php.

◆ get_error()

get_error ( )

Return the last error.

Returns
string
Examples
C:/Develope/SVN/upload/framework/classes/lepton_database.php.

Definition at line 124 of file lepton_database.php.

◆ get_one()

get_one ( string  $SQL)

Execute a SQL query and return the first row of the result array

Parameters
string$SQLAny SQL-Query or statement
Returns
mixed Value of the table-field or null for error
Examples
C:/Develope/SVN/upload/framework/classes/lepton_database.php.

Definition at line 441 of file lepton_database.php.

◆ getInstance()

static getInstance ( array &  $settings = [])
static

Return the (singleton) instance of this class.

Parameters
array$settingsOptional params - see "connect" for details
See also
connect
Examples
C:/Develope/SVN/upload/framework/classes/lepton_handle.php.

Definition at line 75 of file lepton_database.php.

◆ is_error()

is_error ( )

Check if there occurred any error

Returns
boolean
Examples
C:/Develope/SVN/upload/framework/classes/lepton_database.php.

Definition at line 134 of file lepton_database.php.

◆ list_tables()

list_tables ( string  $strip = "")

Returns a linear array within the table-names of the current database

$tables = LEPTON_database::getInstance()->list_tables(TABLE_PREFIX);
if(in_array("my_table",$tables))
{
do this or don't do this
}
Parameters
string$stripA string to 'strip' chars from the table-names, e.g. the prefix.
Returns
array|bool An array within the table-names of the current database, or FALSE (bool).
Examples
C:/Develope/SVN/upload/framework/classes/lepton_database.php.

Definition at line 482 of file lepton_database.php.

◆ query()

query ( string  $sSqlQuery = "")

Execute a SQL query and return a handle to queryMySQL

Parameters
string$sSqlQueryThe query string to be executed.
Returns
object|null Object or null for error
Examples
C:/Develope/SVN/upload/framework/classes/lepton_database.php.

Definition at line 783 of file lepton_database.php.

◆ set_error()

set_error ( string  $error = '')
protected

Set error an error message.

Parameters
string$error
Examples
C:/Develope/SVN/upload/framework/classes/lepton_database.php.

Definition at line 114 of file lepton_database.php.

◆ simple_query()

simple_query ( string  $sMySQL_Query = "",
array  $aParams = [] 
)

Execute a mysql-query without returning a result. A typical use is e.g. "DROP TABLE IF EXIST" or "SET NAMES ..."

Parameters
string$sMySQL_QueryAny (MySQL-) Query
array$aParamsOptional array within the values if place-holders are used.
Returns
int if success number of affected rows
LEPTON_database::getInstance()->simple_query("DROP TABLE `example` IF EXIST");
// or
"INSERT into `TABLE_example` (`name`,`state`) VALUES('?','?');",
array(
['example','none'],
['master', 'confirmed']
)
);
// or
"INSERT into `TABLE_example` (`name`,`state`) VALUES( :name , :sta );",
array(
"name" => "Aldus",
"sta" => "internal"
)
);
Examples
C:/Develope/SVN/upload/framework/classes/lepton_database.php.

Definition at line 404 of file lepton_database.php.

Field Documentation

◆ $bForceDieOnError

bool $bForceDieOnError = true

◆ $bHaltOnError

boolean $bHaltOnError = true

Public var to handle displaying the errors during the processes. (Makes use of LEPTON_tools::display)

@seeAlso LEPTON_tools::display

Examples
C:/Develope/SVN/upload/framework/classes/lepton_database.php.

Definition at line 64 of file lepton_database.php.

◆ DESCRIBE_ASSOC

const DESCRIBE_ASSOC = 1

◆ DESCRIBE_ONLY_NAMES

const DESCRIBE_ONLY_NAMES = 2

◆ DESCRIBE_RAW

const DESCRIBE_RAW = 0

The documentation for this class was generated from the following file: