MySQL functions

Base functions
SetHost(), SetLogin(), SetPassword(), SetBase()

The SetHost(), SetLogin(), SetPassword(), SetBase() functions serve to initialize the variables for the connection.

It's preferable to configure the file TPLN_Cfg.php in TPLN directory to avoid to call these functions every time.

  •  SetHost( string host )
  •  SetLogin( string login )
  •  SetPassword( string password )
  •  SetBase( string base )
example :

SetBase :

$TPLN->SetBase("my_base"); // change default base



 
DbConnect()

The DbConnect() function serves to connect to your MySQL database.

DbConnect( )

example :

DbConnect() :

$TPLN->DbConnect();

 

 
DbClose()

The DbConnect() function serves to connect to your MySQL database.

DbClose( )

example :

DbClose() :

$TPLN->DbClose();

 

 
DoQuery()

The DoQuery() function serves to execute a query.

DoQuery(string query )

example :

DoQuery() :

$TPLN->DoQuery("SELECT * FROM my_table");

 

 
GetData()

The GetData() function serves to return data of your query.
If COUNT parameter is present the result is returned.

GetData( [COUNT] )

example :

GetData() pour un requete normale:

$TPLN->DoQuery("SELECT * FROM my_table");
$res = $TPLN->GetData();

GetData() pour un requete avec count:

$TPLN->DoQuery("SELECT COUNT(*) FROM my_table");
$count = $TPLN->GetData(COUNT);


 
GetRowsCount()

The GetRowsCount() function serves to return the number of rows returned by the query.

GetRowsCount( )

example :

GetRowsCount() :

$TPLN->DoQuery("SELECT * FROM my_table");
$nb_results = $TPLN->GetRowsCount();


 
DBNumRows()

The GetRowsCount() function serves to return the number of rows returned by the query. It's an alias of GetRowsCount()

DBNumRows( )

Exemple :

DBNumRows() :

$TPLN->DoQuery("SELECT * FROM my_table");
$nb_results = $TPLN->DBNumRows();


 
DBFetchArray()

DBFetchArray() serves to return a line of results under an asssociative array.
It's the same as Php function mysql_fetch_array()

DBFetchArray( )

Exemple :

DBFetchArray() :

$TPLN->DoQuery("SELECT * FROM my_table");
while($row = $TPLN->DBFetchArray())
{echo $row["user_id"];}


See also: DBFetchAssoc() and ParseDBrows()

 
DBFetchAssoc()

DBFetchAssoc() serves to return a line of results under an asssociative array.

It's the same as Php function mysql_fetch_assoc()

DBFetchAssoc( )

Exemple :

DBFetchAssoc() :

$TPLN->DoQuery("SELECT * FROM my_table");
while($row = $TPLN->DBFetchAssoc())
{...}


See also: DBFetchArray() andParseDBrows()

 
DBFreeResult()

DBFreeResult() is not to call that if you are afraid to use too much memory during the execution of your script. The whole memory associated to identifying it of result will be freed automatically.

It's the same as Php function mysql_free_result()

DBFreeResult( )


See also: DBFetchArray() et ParseDBrows()

 
ParseDBRow()

ParseDBRow() serves to parse all variables of a bloc by values returned by a row of your query.

ParseDBRow(string bloc)

Exemple :

 

$TPLN->DoQuery("SELECT * FROM my_table");
$TPLN->ParseDbRow("bloc1");


 
ShowRecords() function
ShowRecords()

ShowRecords() is a function that allows you to parse data from MySQL, you only have has create your template and the function takes care of all for you!

Your template must be to configure as this:

  • <bloc::data>
  •    <bloc::loop> </bloc::loop> contains the name of your fields in variable
  •     <bloc::norecord> </bloc::norecord> contains the message if there are not any results
  • </bloc::data>
example :

<html>
<body>

<bloc::data>
  Data<br><br>
  <bloc::loop> {field} <br> </bloc::loop>
   <bloc::norecord>No results</bloc::norecord>

</bloc::data>
</body>
</html>

ShowRecords( string query , int resultsbypage )

example :

ShowRecords() :

$query = "SELECT * FROM my_table";
$TPLN->ShowRecords($query,10);

This function possesses its variable owners who are automatically parsed those must be present in the bloc <bloc::data></bloc::data> they are noted like this {_Variable}.

  • _First indicate the position of the first result
  • _Last indicate the position of the last result
  • _Count indicate the number of results
  • _PageNumber indicate the actual page number
  • _PageCount indicate total page number
  • _UrlBng url of the first page (his text is defined in TPLN_Cfg.php or
    by SetNavLabels() )
  • _UrlPrev url of the previous page (his text is defined in TPLN_Cfg.php or
    by SetNavLabels() )
  • _UrlNext url of the next page (his text is defined in TPLN_Cfg.php or
    by SetNavLabels() )
  • _UrlEnd url of the last page (his text is defined in TPLN_Cfg.php or
    by SetNavLabels() )
  • _UrlPageNav serves for the pagination of your result.
  • _ NavColor replace by one two colors specified in TPLN_Cfg.php or by SetNavColor()
 
SetNavLabels()

The SetNavLabels() function permits to replace the present text in _UrlBng, _UrlPrev, _UrlNext, _UrlEnd.

SetNavLabels(string bngtxt , string prevtxt , string nexttxt , string endtxt )

example :

SetNavLabels() :

$TPLN->SetNavLabels("[<<]","[<]","[>]","[>>]");

 

 
SetNavColor()

The SetNavColor() function permits to alternate color for variable {_NavColor}

SetNavColor(string color1 , string color2 )

example :

SetNavColor() :

$TPLN->SetNavColor("#CCCCCC","#FFFFFF");

 

 
AddUrlVar()

the AddUrlVar() functions permits to add variable in the url of variable _UrlBng, _UrlPrev, _UrlNext, _UrlEnd, _UrlPageNav.

AddUrlVar(string var )

example :

SetNavLabels() :

$TPLN->AddUrlVar("var=my_var");

 

 
AddHtmlUrl()

The AddHtmlUrl() function permits to add html attibuts inside <a [ajout]></a> of _UrlBng, _UrlPrev, _UrlNext, _UrlEnd, _UrlPageNav.

AddHtmlUrl(string string )

example :

SetNavLabels() :

$TPLN->AddHtmlUrl("class=title");// add style title to link

 

 
SetUrl()

SetUrl() permits to change the link of _UrlBng, _UrlPrev, _UrlNext, _UrlEnd, _UrlPageNav.

SetUrl(string url )

If this function is not used the link by default is the php file called.