Overview

Namespaces

  • webfilesframework
    • codegeneration
      • general
      • php
    • core
      • datastore
        • functions
          • filter
          • sorting
        • types
          • database
            • resultHandler
          • directory
          • googlecalendar
          • mail
          • remote
      • datasystem
        • database
        • file
          • format
            • media
              • image
                • handler
          • system
            • dropbox
      • datatypes
        • time
      • time
    • io
      • form
        • formItem
        • validation
        • webfile
      • request

Classes

  • webfilesframework\codegeneration\general\MAbstractClass
  • webfilesframework\codegeneration\general\MAbstractClassAttribute
  • webfilesframework\codegeneration\general\MAbstractClassMethod
  • webfilesframework\codegeneration\general\MAbstractClassMethodParameter
  • webfilesframework\codegeneration\general\MAbstractCodeItem
  • webfilesframework\codegeneration\MCodeItemFactory
  • webfilesframework\codegeneration\MProgrammingLanguage
  • webfilesframework\codegeneration\MWebfileClassGeneration
  • webfilesframework\codegeneration\php\MPhpClassAttribute
  • webfilesframework\codegeneration\php\MPhpClassMethod
  • webfilesframework\codegeneration\php\MPhpClassMethodParameter
  • webfilesframework\codegeneration\php\MPhpWebfileClass
  • webfilesframework\core\datastore\functions\filter\MSubstringFiltering
  • webfilesframework\core\datastore\functions\sorting\MAscendingSorting
  • webfilesframework\core\datastore\functions\sorting\MDescendingSorting
  • webfilesframework\core\datastore\MAbstractCachableDatastore
  • webfilesframework\core\datastore\MAbstractDatastore
  • webfilesframework\core\datastore\MCombinedDatastore
  • webfilesframework\core\datastore\MDatastoreFactory
  • webfilesframework\core\datastore\MDatastoreTransfer
  • webfilesframework\core\datastore\types\database\MDatabaseDatastore
  • webfilesframework\core\datastore\types\database\MSampleWebfile
  • webfilesframework\core\datastore\types\database\resultHandler\MMysqlResultHandler
  • webfilesframework\core\datastore\types\directory\MDirectoryDatastore
  • webfilesframework\core\datastore\types\directory\MDirectoryDatastoreMetainformation
  • webfilesframework\core\datastore\types\directory\MDirectoryDatastoreWebfile
  • webfilesframework\core\datastore\types\googlecalendar\MEvent
  • webfilesframework\core\datastore\types\googlecalendar\MGoogleCalendarDatastore
  • webfilesframework\core\datastore\types\mail\MImapDatastore
  • webfilesframework\core\datastore\types\mail\MMail
  • webfilesframework\core\datastore\types\mail\MMailAccount
  • webfilesframework\core\datastore\types\remote\MRemoteDatastore
  • webfilesframework\core\datastore\types\remote\MRemoteDatastoreEndpoint
  • webfilesframework\core\datasystem\database\MDatabaseConnection
  • webfilesframework\core\datasystem\database\MDatabaseDatatypes
  • webfilesframework\core\datasystem\database\MDatabaseTable
  • webfilesframework\core\datasystem\database\MDatabaseTableColumn
  • webfilesframework\core\datasystem\file\format\media\image\handler\MAbstractImageLibraryHandler
  • webfilesframework\core\datasystem\file\format\media\image\handler\MGdHandler
  • webfilesframework\core\datasystem\file\format\media\image\handler\MImageMagickHandler
  • webfilesframework\core\datasystem\file\format\media\image\MImage
  • webfilesframework\core\datasystem\file\format\media\image\MQrCodeImage
  • webfilesframework\core\datasystem\file\format\media\MYoutubeVideo
  • webfilesframework\core\datasystem\file\format\MWebfile
  • webfilesframework\core\datasystem\file\format\MWebfileStream
  • webfilesframework\core\datasystem\file\system\dropbox\MDropboxAccount
  • webfilesframework\core\datasystem\file\system\dropbox\MDropboxDirectory
  • webfilesframework\core\datasystem\file\system\dropbox\MDropboxFile
  • webfilesframework\core\datasystem\file\system\MDirectory
  • webfilesframework\core\datasystem\file\system\MFile
  • webfilesframework\core\datatypes\time\MTimestampHelper
  • webfilesframework\core\time\MTimespan
  • webfilesframework\core\time\MWeekday
  • webfilesframework\io\form\formItem\MAbstractFormItem
  • webfilesframework\io\form\formItem\MCheckboxesFormItem
  • webfilesframework\io\form\formItem\MDateFormItem
  • webfilesframework\io\form\formItem\MDateTimeFormItem
  • webfilesframework\io\form\formItem\MDropdownMenueFormItem
  • webfilesframework\io\form\formItem\MHiddenFormItem
  • webfilesframework\io\form\formItem\MHtmlTextareaFormItem
  • webfilesframework\io\form\formItem\MPasswordFormItem
  • webfilesframework\io\form\formItem\MTextareaFormItem
  • webfilesframework\io\form\formItem\MTextfieldFormItem
  • webfilesframework\io\form\formItem\MTimeFormItem
  • webfilesframework\io\form\formItem\MWeekdayFormItem
  • webfilesframework\io\form\MForm
  • webfilesframework\io\form\MFormItemFactory
  • webfilesframework\io\form\validation\MValidator
  • webfilesframework\io\form\webfile\MWebfileFormHandler
  • webfilesframework\io\form\webfile\MWebfileFormVisualizer
  • webfilesframework\io\request\MAbstractHttpRequest
  • webfilesframework\io\request\MGetHttpRequest
  • webfilesframework\io\request\MPostHttpRequest
  • webfilesframework\io\request\MUrl

Interfaces

  • webfilesframework\core\datastore\functions\MIDatastoreFunction
  • webfilesframework\core\datastore\MISingleDatasourceDatastore
  • webfilesframework\core\datastore\types\database\resultHandler\MIResultHandler
  • webfilesframework\core\datastore\types\googlecalendar\MISecretStore

Exceptions

  • webfilesframework\core\datastore\MDatastoreException
  • webfilesframework\core\datastore\types\database\MDatabaseDatastoreException
  • webfilesframework\MWebfilesFrameworkException
  • Overview
  • Namespace
  • Class
  1: <?php
  2: 
  3: namespace webfilesframework\core\datasystem\database;
  4: 
  5: use webfilesframework\core\datastore\types\database\resultHandler\MIResultHandler;
  6: use webfilesframework\core\datastore\types\database\resultHandler\MMysqlResultHandler;
  7: use webfilesframework\MWebfilesFrameworkException;
  8: 
  9: /**
 10:  * description
 11:  *
 12:  * @author     Sebastian Monzel < mail@sebastianmonzel.de >
 13:  * @since      0.1.7
 14:  */
 15: class MDatabaseConnection
 16: {
 17:     private $host = '127.0.0.1';
 18: 
 19:     private $databaseName = 'webfiles';
 20:     private $tablePrefix = 'default_';
 21: 
 22:     private $username = 'root';
 23:     private $password = '';
 24: 
 25:     /** @var \mysqli $connection */
 26:     private $connection;
 27: 
 28:     static private $instanceArray = array();
 29: 
 30:     /**
 31:      *
 32:      * @param string $host the host to connect to.
 33:      * @param string $database the database to connect to.
 34:      * @param string $tablePrefix the table prefix used for the actual connection to the database.
 35:      * @param string $username the username for the connection.
 36:      * @param string $password the password for the connection.
 37:      */
 38:     public function __construct(
 39:         $host = null,
 40:         $database = null,
 41:         $tablePrefix = null,
 42:         $username = null,
 43:         $password = null)
 44:     {
 45: 
 46:         if ($host != null) {
 47:             $this->host = $host;
 48:         }
 49:         if ($database != null) {
 50:             $this->databaseName = $database;
 51:         }
 52:         if ($tablePrefix != null) {
 53:             $this->tablePrefix = $tablePrefix;
 54:         }
 55:         if ($username != null) {
 56:             $this->username = $username;
 57:         }
 58:         if ($password != null) {
 59:             $this->password = $password;
 60:         }
 61: 
 62:         $this->connect();
 63:     }
 64: 
 65:     /**
 66:      * multiton to administrate the instances of the connection
 67:      * and global accessing
 68:      *
 69:      * @param String $instanceName
 70:      * @return object
 71:      */
 72:     static public function getInstance($instanceName)
 73:     {
 74:         if (!isset(self::$instanceArray[$instanceName])) {
 75:             self::$instanceArray[$instanceName] = new MDatabaseConnection();
 76:         }
 77:         return self::$instanceArray[$instanceName];
 78:     }
 79: 
 80:     /**
 81:      * connects to the database server
 82:      */
 83:     public function connect()
 84:     {
 85:         $this->connection = @new \mysqli(
 86:             $this->host,
 87:             $this->username,
 88:             $this->password,
 89:             $this->databaseName
 90:         );
 91: 
 92:         if (!$this->connection->connect_errno) {
 93:             $this->connection->autocommit(1);
 94:             return true;
 95:         } else {
 96:             echo mysqli_connect_error();
 97:             return false;
 98:         }
 99:     }
100: 
101:     /**
102:      * closes the connection
103:      */
104:     public function close()
105:     {
106:         @$this->connection->close();
107:     }
108: 
109:     /**
110:      * queries the database with the specified sql command
111:      *
112:      * @param $sqlCommand
113:      *
114:      * @return bool|\mysqli_result
115:      * @throws MWebfilesFrameworkException
116:      */
117:     public function query($sqlCommand)
118:     {
119:         $result = $this->connection->query($sqlCommand);
120:         if ($this->getError() != null ) {
121:             throw new MWebfilesFrameworkException("Error orrured on executing sql: " . $this->getError() .", SQL: " . $sqlCommand);
122:         }
123: 
124:         return $result;
125:     }
126: 
127:     /**
128:      * @param $sqlCommand
129:      *
130:      * @return MIResultHandler
131:      * @throws MWebfilesFrameworkException
132:      */
133:     public function queryAndHandle($sqlCommand)
134:     {
135:         $result = $this->query($sqlCommand);
136:         if ($this->getError() != null ) {
137:             throw new MWebfilesFrameworkException("Error orrured on executing sql: " . $this->getError() .", SQL: " . $sqlCommand);
138:         }
139:         return new MMysqlResultHandler($result);
140:     }
141: 
142:     /**
143:      * prints last error of the connection
144:      */
145:     public function getError()
146:     {
147:         return $this->connection->error;
148:     }
149: 
150:     /**
151:      * returns id of a last insert query
152:      *
153:      * @return int
154:      */
155:     public function getInsertId()
156:     {
157:         return $this->connection->insert_id;
158:     }
159: 
160:     /**
161:      * returns the hostname of the databaseserver
162:      *
163:      * @access public
164:      * @return String
165:      */
166:     public function getHost()
167:     {
168:         return $this->host;
169:     }
170: 
171:     /**
172:      * returns the name of the user connected to the database server
173:      *
174:      * @access public
175:      * @return String
176:      */
177:     public function getUsername()
178:     {
179:         return $this->username;
180:     }
181: 
182:     /**
183:      * @return null|string
184:      */
185:     public function getPassword()
186:     {
187:         return $this->password;
188:     }
189: 
190:     /**
191:      * @return null|string
192:      */
193:     public function getDatabaseName()
194:     {
195:         return $this->databaseName;
196:     }
197: 
198:     /**
199:      * Sets the database for the given connection
200:      * @access public
201:      * @param $databaseName
202:      */
203:     public function setDatabaseName($databaseName)
204:     {
205:         $this->databaseName = $databaseName;
206:     }
207: 
208:     /**
209:      * Returns the table prefix used for the given
210:      * connection.
211:      */
212:     public function getTablePrefix()
213:     {
214:         return $this->tablePrefix;
215:     }
216: 
217: }
218: 
API documentation generated by ApiGen