rootpackage
[ class tree: rootpackage ] [ index: rootpackage ] [ all elements ]

Class: MySQL

Source Location: /MySQL.php

Class Overview


Created on 14-aug-06


Author(s):

Version:

  • 2.0

Variables

Methods



Class Details

[line 16]
Created on 14-aug-06

This class manages MySQL connections. With this class, you can use SELECT, INSERT, UPDATE, MATCH, DELETE, DROP and show specific columns data.

Changes: 1.0 to 2.0: phpdoc compatible in the way to generate documentation




Tags:

author:  Pierre-Dominique Vienne <pvienne@me.com>
version:  2.0
license:  GNU Public License


[ Top ]


Class Variables

$complex_query =

[line 101]

Variable defining the complete query to send to MySQL::sql_link.



Tags:

access:  public

Type:   string


[ Top ]

$database =

[line 39]

Variable that defines the database name.



Tags:

access:  public

Type:   string


[ Top ]

$dbhost =  "localhost"

[line 22]

Variable that defines the server where the database is.



Tags:

access:  public

Type:   string


[ Top ]

$dbpass =  "ajYz7yhrcUAX8ZAu"

[line 34]

Variable that defines the password with which you will connect.



Tags:

access:  public

Type:   string


[ Top ]

$dbuser =  "webuser"

[line 28]

Variable that defines the user with which you will connect.



Tags:

access:  public

Type:   string


[ Top ]

$debug =  false

[line 121]

Variable defining the debug mode. If defined to true, the object will echo the query.



Tags:

access:  public

Type:   bool


[ Top ]

$distinct =  false

[line 64]

Variable defining if the SELECT must be distinct or not.



Tags:

access:  public

Type:   bool


[ Top ]

$error_report =  "change to your mysql-master email"

[line 116]

Variable defining the email to throw when errors are displayed.



Tags:

access:  protected

Type:   string


[ Top ]

$fetch_method =  MYSQLI_ASSOC

[line 111]

Variable defining the method used to fetch the results.



Tags:

access:  public

Type:   const


[ Top ]

$groupby =  false

[line 69]

Variable defining if the SELECT must group the results by a specific column.



Tags:

access:  public

Type:   bool|string


[ Top ]

$leftjoin =

[line 54]

Variable containing left join statement used in SELECT.



Tags:

access:  public

Type:   array


[ Top ]

$limitfrom =

[line 85]

Variable defining the limit from to use. ... LIMIT $limitfrom,$limitqty; If this variable is not defined, no limit is used.



Tags:

access:  public

Type:   int


[ Top ]

$limitqty =

[line 91]

Variable defining the limit quantity to use. ... LIMIT $limitfrom,$limitqty; If this variable is not defined, no limit is used.



Tags:

access:  public

Type:   int


[ Top ]

$matchvalue =  1

[line 96]

Variable defining the HAVING minimal value for match selection.



Tags:

access:  public

Type:   int


[ Top ]

$order =  "ASC"

[line 79]

Variable defining the way the results need to be ordered (Ascending / Descending).



Tags:

access:  public

Type:   string


[ Top ]

$orderrow =

[line 74]

Variable defining the row to use to order the results.



Tags:

access:  public

Type:   string


[ Top ]

$result =

[line 106]

Variable where the result of a select is stored.



Tags:

access:  public

Type:   array


[ Top ]

$sql_link =

[line 49]

Variable where the sql link is stored.



Tags:

access:  public

Type:   object


[ Top ]

$table =

[line 44]

Variable that defines the table name.



Tags:

access:  public

Type:   string


[ Top ]

$whereclause =  1

[line 59]

Variable defining the WHERE clause.



Tags:

access:  public

Type:   string


[ Top ]



Class Methods


constructor __construct [line 151]

MySQL __construct( [array $aParams = null], [string $sAction = null])

Construction function

This function is used when object is generated. It places variables in "$this" var and can launch function

  1.  <?php
  2.  $aParams        array("database"=>"testdb");
  3.  $oMySQL        new MySQL($aParams)
  4.  echo $oMySQL->database;
  5.  // testdb
  6.  ?>




Tags:

since:  Version 1.0
uses:  Strings


Parameters:

array   $aParams   array containing variable names and their value ($variablename => $value)
string   $sAction   string containing action to perform on object creation

[ Top ]

method ComplexQuery [line 705]

int|bool ComplexQuery( object $this->sql_link, string $this->database, string $this->complex_query, bool $this->debug)

Special complex query function

This function is used to send special complex query using MySQL::sql_link

  1.  <?php
  2.  $complexquery    "SELECT foo AS bar FROM testtable WHERE SUM(col1,col2)=10;";
  3.  $aParams            array("database"=>"testdb","table"=>"testtable","complex_query"=>$complexquery);
  4.  $oMySQL            new MySQL($aParams,"ComplexQuery");
  5.  print_r($oMySQL->result);
  6.  //Displays all rows matching $complexquery
  7.  ?>




Tags:

return:  quantity of affected rows if the query could be applied
since:  Version 1.0
uses:  MySQL::ConnectDB()


Parameters:

object   $this->sql_link   SQL link to database
string   $this->database   database name (required)
string   $this->complex_query   query to be sent (required)
bool   $this->debug   defines if the function needs to echo the query

[ Top ]

method ConnectDB [line 197]

bool ConnectDB( string $this->dbhost, string $this->dbuser, string $this->dbpass, string $this->database)

Function to connect to database

This function is used to connect to database.

  1.  <?php
  2.  $oMySQL        new MySQL();
  3.  $oMySQL->ConnectDB();
  4.  print_r($oMySQL->sql_link);
  5.  // Object corresponding to SQL link
  6.  ?>




Tags:

return:  true if the connection could be completed
since:  Version 1.0
usedby:  MySQL::MatchTerms()
usedby:  MySQL::ComplexQuery()
usedby:  MySQL::ShowColumns()
usedby:  MySQL::EmptyTable()
usedby:  MySQL::UpdateRow()
usedby:  MySQL::InsertDatas()
usedby:  MySQL::SelectRow()
usedby:  MySQL::DeleteRow()


Parameters:

string   $this->dbhost   database host (required)
string   $this->dbuser   database user (required)
string   $this->dbpass   database password (required)
string   $this->database   database name (required)

[ Top ]

method DeleteRow [line 435]

int|bool DeleteRow( object $this->sql_link, string $this->database, string $this->table, string $this->whereclause, string $this->orderrow, string $this->order, int $this->limitfrom, string $this->limitqty, bool $this->debug)

Data deletion function

This function is used to delete rows using MySQL::sql_link

  1.  <?php
  2.  $aParams        array("database"=>"testdb","table"=>"testtable","whereclause"=>"row2=2");
  3.  $oMySQL        new MySQL($aParams);
  4.  $oMySQL->DeleteRow();
  5.  ?>




Tags:

return:  quantity of the deleted rows or false if the query could not be applied
since:  Version 1.0
uses:  MySQL::ConnectDB()


Parameters:

object   $this->sql_link   SQL link to database
string   $this->database   database name (required)
string   $this->table   table name (required)
string   $this->whereclause   where clause statement
string   $this->orderrow   column with which making an order by statement
string   $this->order   order to apply (ASCENDING / DESCENDING)
int   $this->limitfrom   integer defining the limit from statement
string   $this->limitqty   integer defining the limit quantity
bool   $this->debug   defines if the function needs to echo the query

[ Top ]

method EmptyTable [line 566]

bool EmptyTable( object $this->sql_link, string $this->database, string $this->table, bool $this->debug)

Table reset function

This function is used to empty a table using MySQL::sql_link

  1.  <?php
  2.  $aParams        array("database"=>"testdb","table"=>"testtable");
  3.  $oMySQL        new MySQL($aParams);
  4.  $oMySQL->EmptyTable();
  5.  ?>




Tags:

return:  true if the table could be emptied
since:  Version 1.0
uses:  MySQL::ConnectDB()


Parameters:

object   $this->sql_link   SQL link to database
string   $this->database   database name (required)
string   $this->table   table name (required)
bool   $this->debug   defines if the function needs to echo the query

[ Top ]

method InsertDatas [line 253]

int|bool InsertDatas( array $rows, array $datas, object $this->sql_link, string $this->database, string $this->table, bool $this->debug)

Data insertion function

This function is used to insert data using MySQL::sql_link

  1.  <?php
  2.  $aParams        array("database"=>"testdb","table"=>"testtable");
  3.  $oMySQL        new MySQL($aParams);
  4.  $aRows        array("row1","row2","row3");
  5.  $aValue        array("test",2,"value");
  6.  $oMySQL->InsertDatas($aRows,$aValue);
  7.  ?>




Tags:

return:  id of the inserted row or false if the query could not be applied
since:  Version 1.0
usedby:  WBobject::addToDB()
usedby:  EW_Manufacturers::ManufacturerAdd()
usedby:  BlueBox_CacheControl::InsertQuery()
uses:  MySQL::ConnectDB()
usedby:  EW_Manufacturer_Models::ModelAdd()


Parameters:

object   $this->sql_link   SQL link to database
array   $rows   rows that will be completed with values (required)
array   $datas   values to put in specific rows (required)
string   $this->database   database name (required)
string   $this->table   table name (required)
bool   $this->debug   defines if the function needs to echo the query

[ Top ]

method MatchTerms [line 631]

int|bool MatchTerms( array $rows2show, array $rows2search, string $searchterm, object $this->sql_link, string $this->database, string $this->table, string $order, string $limitfrom, string $limit, bool $this->debug)

Match term function

This function is used to match a term in specific rows using MySQL::sql_link

  1.  <?php
  2.  $aParams            array("database"=>"testdb","table"=>"testtable");
  3.  $oMySQL            new MySQL($aParams);
  4.  $aCols2show        array("col1","col2");
  5.  $aCols2search    array("col2","col4");
  6.  $searchterm        "football";
  7.  $oMySQL->MatchTerms($aCols2show,$aCols2search,$searchterm);
  8.  print_r($oMySQL->result);
  9.  //Displays all rows matching searchterm in col2 and col4. It shows only col1 and col2.
  10.  ?>




Tags:

return:  quantity of fetched rows if the query could be applied
since:  Version 1.0
uses:  MySQL::ConnectDB()


Parameters:

object   $this->sql_link   SQL link to database
string   $this->database   database name (required)
string   $this->table   table name (required)
array   $rows2show   rows to be displayed
array   $rows2search   rows in which search will be performed
string   $searchterm   term that will be searched in rows
string   $order   order to use (ASCENDING / DESCENDING)
string   $limitfrom   limit from value
string   $limit   quantity limit quantity to show
bool   $this->debug   defines if the function needs to echo the query

[ Top ]

method SelectRow [line 337]

int|bool SelectRow( [array $rows = "*"], object $this->sql_link, string $this->database, string $this->table, string $this->whereclause, bool $this->distinct, array $this->leftjoin, string $this->groupby, string $this->orderrow, int $this->limitfrom, string $this->limitqty, bool $this->debug)

Data selection function

This function is used to select data using MySQL::sql_link

  1.  <?php
  2.  $aParams        array("database"=>"testdb","table"=>"testtable","whereclause"=>"row2=2");
  3.  $oMySQL        new MySQL($aParams);
  4.  $aRows        array("row1","row2","row3");
  5.  $oMySQL->SelectRow($aRows);
  6.  print_r($oMySQL->result);
  7.  // Displays all rows where column "row2=2". It will only show "row1", "row2" and "row3"
  8.  ?>




Tags:



Parameters:

object   $this->sql_link   SQL link to database
array   $rows   rows that will be completed with values (required)
string   $this->database   database name (required)
string   $this->table   table name (required)
string   $this->whereclause   where clause statement
bool   $this->distinct   defines if the selection needs to be distinct or not
array   $this->leftjoin   used when left join statement has to be used
string   $this->groupby   column with which making a group by statement
string   $this->orderrow   column with which making an order by statement
int   $this->limitfrom   integer defining the limit from statement
string   $this->limitqty   integer defining the limit quantity
bool   $this->debug   defines if the function needs to echo the query

[ Top ]

method ShowColumns [line 769]

array ShowColumns( [string $rows = "*"], object $this->sql_link, string $this->database, string $this->table, bool $this->debug)

Show Columns function

This function is used to show columns and their info from a table using MySQL::sql_link

  1.  <?php
  2.  $aParams            array("database"=>"testdb","table"=>"testtable");
  3.  $oMySQL            new MySQL($aParams,"ComplexQuery");
  4.  print_r($oMySQL->result);
  5.  //Displays all rows matching $complexquery
  6.  ?>




Tags:

return:  PHP array corresponding to columns informations
since:  Version 1.0
uses:  MySQL::ConnectDB()


Parameters:

object   $this->sql_link   SQL link to database
string   $this->database   database name (required)
string   $this->table   table name (required)
string   $rows   rows to be shown
bool   $this->debug   defines if the function needs to echo the query

[ Top ]

method UpdateRow [line 496]

int|bool UpdateRow( array $rows, array $datas, object $this->sql_link, string $this->database, string $this->table, string $this->whereclause, bool $this->debug)

Data update function

This function is used to update rows using MySQL::sql_link

  1.  <?php
  2.  $aParams        array("database"=>"testdb","table"=>"testtable","whereclause"=>"row2=2");
  3.  $oMySQL        new MySQL($aParams);
  4.  $aRows        array("row1","row2","row3");
  5.  $aValue        array("foo","bar",12);
  6.  $oMySQL->UpdateRow($aRows,$aValue);
  7.  ?>




Tags:

return:  quantity of the updated rows or false if the query could not be applied
since:  Version 1.0
usedby:  WBobject::deleteFromDB()
usedby:  WBobject::updateDB()
usedby:  EW_Manufacturer_Models::ModelUpdate()
uses:  MySQL::ConnectDB()
usedby:  EW_Manufacturers::ManufacturerUpdate()


Parameters:

object   $this->sql_link   SQL link to database
string   $this->database   database name (required)
string   $this->table   table name (required)
array   $rows   rows to be updated
array   $datas   datas to apply in rows
string   $this->whereclause   where clause statement
bool   $this->debug   defines if the function needs to echo the query

[ Top ]


Documentation generated on Wed, 26 Aug 2009 12:30:30 +0200 by phpDocumentor 1.4.1