External Library

phptricks PDO Class

Logaty Using phptricks PDO Class
its library (class) to ease use database with PDO extension
You can see Documentation of this class on :
phptricks PDO Class On github

phptricks PDO Class Settings & Options

Settings & Options

Go to logaty/inc/classes/Libs/database_config.php

  • fetch

    choice how you need to fetch data (as array or object)

  • default

    choice database driver your project use

    supported drivers :

    mysql pgsql sqlite mssql sybase oci - Oracle
  • connections

    Go to chosen driver key and put access database information

    database host database name database username database password database host
RETRIEVE TRANSLATION from database

DB Class (Video)

its very easy to use, you can using 'DBTranslator' class direct or create your owen Models
everything describe in this video

How to Use

In all examples below, we assume that we have a table in the database called "articles"
and table structure like this
id ar_title en_title de_title ar_body en_body de_body views created_by trans
int varchar(255) varchar(255) varchar(255) Long Text Long Text Long Text int int varchar(20)

pleas note : the 'trans' field is required, its contain localized language codes by this row Separated by commas

  • Using Direct
    
    use PHPtricks\Logaty\DBTranslator;
    $translator = new DBTranslator();
    // choice the table
    $translator->setTable("articles");
    /* set Localizable fields in this case its (ar_title, en_title, de_title, ar_body, en_body and de_body)
     * so the Localizable fields its (title and body)
    */
    $translator->setFields(["title", "body"]);
    
    // if id columns name is not (id)
    // $translator->setIdColumn("id_name");
    
    // now if we want a single article
    $article = $translator->getOne($id);
    var_dump($article);
    // the output must be a content of current language if its translated to that language
    // otherwise the output be in default language or message for user (this content is not available in selected language)
    // see config.php file documentation
    
    // if we want all of articles
    $articles = $translator->getAll();
    var_dump($articles);
    // the output must be all contents of current language only
    // or all contents with not translated hint by message for user (this content is not available in selected language)
    // see config.php file documentation
    
                            
  • Create Models
    
    use PHPtricks\Logaty\DBTranslator;
    class Model extends DBTranslator
        // choice the table
        protected $_table = "articles";
        /* set Localizable fields in this case its (ar_title, en_title, de_title, ar_body, en_body and de_body)
         * so the Localizable fields its (title and body)
        */
        protected $_fields = ["title", "body"];
    
        // if id columns name is not (id)
        // protected $idColumn = "id_name";
    
        // now if we want a single article
        public function getSingle($id)
        {
            // you can do something here
            return $this->getOne($id);
            // the output must be a content of current language if its translated to that language
            // otherwise the output be in default language or message for user (this content is not available in selected language)
            // see config.php file documentation
        }
    
        // if we want all of articles
        public function getAllFromTable()
        {
            // do something here
            return $translator->getAll()
            // the output must be all contents of current language only
            // or all contents with not translated hint by message for user (this content is not available in selected language)
            // see config.php file documentation
        }
    }
    
                            
  • Video

    SOON