Overview

Namespaces

  • Kotchasan
    • Cache
    • Database
    • Http
    • Log
    • Orm
  • None
  • PHP
  • Psr
    • Cache
    • Http
      • Message
    • Log

Classes

  • ArrayIterator
  • DateInterval
  • DOMNode
  • Kotchasan
  • Kotchasan\Accordion
  • Kotchasan\ApiController
  • Kotchasan\ArrayTool
  • Kotchasan\Cache\ApcCache
  • Kotchasan\Cache\Cache
  • Kotchasan\Cache\CacheItem
  • Kotchasan\Cache\FileCache
  • Kotchasan\CKEditor
  • Kotchasan\Collection
  • Kotchasan\Config
  • Kotchasan\Controller
  • Kotchasan\Country
  • Kotchasan\Csv
  • Kotchasan\Curl
  • Kotchasan\Currency
  • Kotchasan\Database
  • Kotchasan\Database\Db
  • Kotchasan\Database\DbCache
  • Kotchasan\Database\Driver
  • Kotchasan\Database\PdoMysqlDriver
  • Kotchasan\Database\Query
  • Kotchasan\Database\QueryBuilder
  • Kotchasan\Database\Schema
  • Kotchasan\Database\Sql
  • Kotchasan\DataTable
  • Kotchasan\Date
  • Kotchasan\DOMNode
  • Kotchasan\DOMParser
  • Kotchasan\Email
  • Kotchasan\File
  • Kotchasan\Files
  • Kotchasan\Form
  • Kotchasan\Grid
  • Kotchasan\Html
  • Kotchasan\Htmldoc
  • Kotchasan\HtmlTable
  • Kotchasan\Http\AbstractMessage
  • Kotchasan\Http\AbstractRequest
  • Kotchasan\Http\Message
  • Kotchasan\Http\NotFound
  • Kotchasan\Http\Request
  • Kotchasan\Http\Response
  • Kotchasan\Http\Stream
  • Kotchasan\Http\UploadedFile
  • Kotchasan\Http\Uri
  • Kotchasan\Image
  • Kotchasan\InputItem
  • Kotchasan\Inputs
  • Kotchasan\KBase
  • Kotchasan\Language
  • Kotchasan\ListItem
  • Kotchasan\Log\AbstractLogger
  • Kotchasan\Log\Logger
  • Kotchasan\Login
  • Kotchasan\Menu
  • Kotchasan\Mime
  • Kotchasan\Model
  • Kotchasan\Number
  • Kotchasan\ObjectTool
  • Kotchasan\Orm\Field
  • Kotchasan\Orm\Recordset
  • Kotchasan\Password
  • Kotchasan\Pdf
  • Kotchasan\Province
  • Kotchasan\Router
  • Kotchasan\Session
  • Kotchasan\Singleton
  • Kotchasan\Tab
  • Kotchasan\TableRow
  • Kotchasan\Template
  • Kotchasan\Text
  • Kotchasan\Validator
  • Kotchasan\View
  • PHPMailer
  • Psr\Log\AbstractLogger
  • Psr\Log\LogLevel
  • Psr\Log\NullLogger
  • SMTP

Interfaces

  • ArrayAccess
  • Countable
  • DateTimeInterface
  • Iterator
  • IteratorAggregate
  • Psr\Cache\CacheItemInterface
  • Psr\Cache\CacheItemPoolInterface
  • Psr\Http\Message\MessageInterface
  • Psr\Http\Message\RequestInterface
  • Psr\Http\Message\ResponseInterface
  • Psr\Http\Message\ServerRequestInterface
  • Psr\Http\Message\StreamInterface
  • Psr\Http\Message\UploadedFileInterface
  • Psr\Http\Message\UriInterface
  • Psr\Log\LoggerAwareInterface
  • Psr\Log\LoggerInterface
  • SeekableIterator
  • Serializable
  • Traversable

Traits

  • Psr\Log\LoggerTrait

Exceptions

  • Exception
  • InvalidArgumentException
  • Kotchasan\ApiException
  • Kotchasan\Cache\Exception
  • Kotchasan\Database\Exception
  • Kotchasan\InputItemException
  • LogicException
  • phpmailerException
  • RuntimeException

Functions

  • createClass
  • debug
  • getClassPath
  • Overview
  • Namespace
  • Class
  • Tree
 1: <?php
 2: /**
 3:  * @filesource Kotchasan/Database/Schema.php
 4:  *
 5:  * @copyright 2016 Goragod.com
 6:  * @license http://www.kotchasan.com/license/
 7:  *
 8:  * @see http://www.kotchasan.com/
 9:  */
10: 
11: namespace Kotchasan\Database;
12: 
13: /**
14:  * Database schema.
15:  *
16:  * @author Goragod Wiriya <admin@goragod.com>
17:  *
18:  * @since 1.0
19:  */
20: class Schema
21: {
22:     /**
23:      * Database object
24:      *
25:      * @var Driver
26:      */
27:     private $db;
28:     /**
29:      * รายการ Schema ที่โหลดแล้ว
30:      *
31:      * @var array
32:      */
33:     private $tables = array();
34: 
35:     /**
36:      * Create Schema Class
37:      *
38:      * @param Driver $db
39:      *
40:      * @return \static
41:      */
42:     public static function create(Driver $db)
43:     {
44:         $obj = new static();
45:         $obj->db = $db;
46:         return $obj;
47:     }
48: 
49:     /**
50:      * อ่านรายชื่อฟิลด์ของตาราง
51:      * คืนค่ารายชื่อฟิลด์ทั้งหมดในตาราง.
52:      *
53:      * @return array
54:      */
55:     public function fields($table)
56:     {
57:         if (empty($table)) {
58:             throw new \InvalidArgumentException('table name empty in fields');
59:         } else {
60:             $this->init($table);
61:             return array_keys($this->tables[$table]);
62:         }
63:     }
64: 
65:     /**
66:      * อ่านข้อมูล Schema จากตาราง.
67:      *
68:      * @param string $table
69:      */
70:     private function init($table)
71:     {
72:         if (empty($this->tables[$table])) {
73:             $sql = "SHOW FULL COLUMNS FROM $table";
74:             $columns = $this->db->cacheOn()->customQuery($sql, true);
75:             if (empty($columns)) {
76:                 throw new \InvalidArgumentException($this->db->getError());
77:             } else {
78:                 $datas = array();
79:                 foreach ($columns as $column) {
80:                     $datas[$column['Field']] = $column;
81:                 }
82:                 $this->tables[$table] = $datas;
83:             }
84:         }
85:     }
86: }
87: 
Kotchasan API documentation generated by ApiGen