POT
POT
POT
Main menu

Download

Forum

SVN

Prev Next

Basics

Most important things you have to know in order to use POT.

Table of Contents

POT basics

Most important is to understand how it all works. POT provides classes to abstract many OTServ resources. Main class of toolkit is named POT. Many resource handlers are assigned to POT instance.

POT class instance

POT class implements singleton pattern. It means you should use only one instance of this class everywhere. Thanks to PHP5 and methods access definers, it's constructor was restricted to private so you won't even be able to create more instances. This might seem quite odd for you - you won't create object directly. To get POT class instance you have to use getInstance() method. In next section you will see example how to call this method.

What is it for? POT class defines entire enviroment for working with OTServ. In single instance you define all resources needed to work with given server. And now imagine you would want to move that enviroment into another scope, for example into function. Since singleton is a static instance, there is no problem with that. You just fetch the very same enviroment every time you call POT::getInstance().


Database connection

Probably the most important part of this toolkit is database operations part. To execute any operations on database you first have to connect. POT supports 4 SQL drivers: MySQL, SQLite, PgSQL and ODBC. Each of those drivers has different connection parameters list so look into theirs documentation for details. To connect with database you use connect() method.

  1. <?php
  2.  
  3. // includes POT main file
  4. include_once('classes/OTS.php');
  5.  
  6. // database configuration - can be simply moved to external file, eg. config.php
  7. $config array(
  8.     'driver' => POT::DB_MYSQL,
  9. //    'prefix' => '',
  10.     'host' => 'localhost',
  11.     'user' => 'wrzasq',
  12. //    'password' => '',
  13.     'database' => 'otserv'
  14. );
  15.  
  16. // creates POT instance (or get existing one)
  17. $ots POT::getInstance();
  18. $ots->connect(null$config);
  19. // could be: $ots->connect(POT::DB_MYSQL, $config);
  20.  
  21. ?>

To execute particular operations you will use objects and it's usage will be described in further parts of this tutorial.

PDO

As a core for database handle PDO instance is used. You can get pure connection handle which will enable you to execute SQL queries directly by calling getDBHandle() method on connected POT instance.



Changing directory

As you probably noticed the only one file which you include is OTS.php. But you have to keep all POT files in one directory. If you wan't to have main file somewhere in your autoloaded directories and keep your directories tree clean from all additional POT files, you can use setPOTPath() method:

  1. <?php
  2.  
  3. // this is the way you should work with POT if you moved main OTS.php file outside POT's directory
  4. include('path/to/OTS.php');
  5.  
  6. // dont use 'new POT()'!!!
  7. $ots POT::getInstance();
  8. $ots->setPOTPath('classes');
  9.  
  10. /*
  11.     here comes your stuff...
  12. */
  13.  
  14. ?>


Quick start

So to put that all together, in order to start working with POT you have to:

  1. Load main toolkit file (OTS.php).
  2. Create POT instance by calling POT::getInstance() first time.
  3. Connect to database.

When you will use POT also for working with non-database resources then you will also mostly have to load global instances for some of them.

Prev Up Next
POT POT PHP 5.0