本文整理汇总了PHP中DatabaseManager::instance方法的典型用法代码示例。如果您正苦于以下问题:PHP DatabaseManager::instance方法的具体用法?PHP DatabaseManager::instance怎么用?PHP DatabaseManager::instance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DatabaseManager
的用法示例。
在下文中一共展示了DatabaseManager::instance方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: checkTable
/**
* Checks the currently existing table against the provided SQL schema in its associated file
*
* @param string $table The name of the table to check
*/
private function checkTable($table)
{
// Get the fields from the existing table
$fields = DatabaseManager::instance()->Table($table)->fetchAll(PDO::FETCH_COLUMN);
// Get the table schema from the table structure in the file
$schema = $this->grabTableInfo($table)[0];
// Get the fields/columns from the schema - these will be used for comparison
$columns = $schema->Columns();
// Get the keys from the schema - used to determine if the key needs to be added
$keys = $schema->Keys();
$toAdd = [];
// Compare the current table fields to the files fields
for ($i = 0; $i < count($columns); $i++) {
$add = true;
// Get the current column name
$colname = $columns[$i]['name'];
// Check to see if the column name from the schema exists in the current table schema
for ($j = 0; $j < count($fields); $j++) {
// If the column does exist, skip it
if ($colname == $fields[$j]) {
$add = false;
break;
}
}
// If the column does not exist, add it to the list of columns that need to be re-added
if ($add) {
$toAdd[count($toAdd)] = $columns[$i];
}
}
// If there are any columns to be added, add them.
// This check might be redundant as technically it should not get here unless there are columns missing.
if (count($toAdd) > 0) {
$this->alterTable($table, $toAdd, $keys);
}
}
示例2: getInstance
public static function getInstance()
{
if (self::$instance == null) {
$className = __CLASS__;
self::$instance = new $className();
}
return self::$instance;
}
示例3: getInstance
private static function getInstance()
{
if (!self::$instance) {
// If no instance then make one
self::$instance = new self();
}
return self::$instance->dbConnection;
}
示例4: resetInstance
/**
* Reset the internal static instance
*
* @return void
*/
public static function resetInstance()
{
if (!self::$instance) {
return;
}
self::$instance->reset();
self::$instance = null;
}