public static function getInstance() { if (!self::$m_instance) { self::$m_instance = new self(); } return self::$m_instance; }
<?php require_once dirname(dirname(dirname(dirname(__FILE__)))) . "/etc/__autoload.php"; $projectName = PROJECT; function tr_color($i) { if ($i % 2) { // $i が奇数 return "#F5F5F5"; } else { // $i が偶数 return "#DCDCDC"; } } // ここからデータベースを操作 $dbOBJ = DatabaseAccess::getInstance(); $sql = "SHOW TABLES"; $rtn_table = $dbOBJ->executeQuery($sql); $k = 1; while ($d = $rtn_table->fetchAssoc()) { foreach ($d as $v) { if ($_REQUEST["db_table"] == $k) { $option_tag .= "<option value=\"" . $_SERVER["PHP_SELF"] . "?db_table=" . $k . "\" selected>" . $v . "</option>\n"; $tbl_number = $k; } else { $option_tag .= "<option value=\"" . $_SERVER["PHP_SELF"] . "?db_table=" . $k . "\">" . $v . "</option>\n"; } $db_table_array[$k] = $v; } $k++; }
<?php class DatabaseAccess { public static $shouldCache = false; public function getData() { if (self::$shouldCache == true) { return 'data from cache'; } else { return 'data from database'; } } } // getting user data! $db = new DatabaseAccess(); $data = $db->getData(); echo $data; echo '<br>'; // getting a blog post, now we want caching DatabaseAccess::$shouldCache = true; $db1 = new DatabaseAccess(); $data = $db1->getData(); echo 'DB1 data: ' . $data; echo '<br>'; DatabaseAccess::$shouldCache = false; $db2 = new DatabaseAccess(); $data = $db2->getData(); echo 'DB2 data: ' . $data; echo '<br>';
function ItemParser() { parent::DatabaseAccess(); }
// create database echo 'Check database...'; $database_selected = mysqli_select_db($connection, $database_name); if (!$database_selected) { echo "not exists" . PHP_EOL; $sql = "CREATE DATABASE {$database_name}"; if (!mysqli_query($connection, $sql)) { echo "\t=>Error when creating database `{$database_name}`: " . mysql_error() . PHP_EOL; exit; } echo "\tCreate database `{$database_name}`...done" . PHP_EOL . PHP_EOL; } else { echo 'ok' . PHP_EOL . PHP_EOL; } // create tables $db_obj = new DatabaseAccess(); $new_table_array = array(); foreach (glob(TABLE_SQL_ROOT . '/*.sql') as $sql_file) { $new_table_array[] = str_replace('.sql', '', str_replace(TABLE_SQL_ROOT . '/', '', $sql_file)); } foreach ($new_table_array as $table_name) { $class_name = str_replace(' ', '', ucwords(str_replace('_', ' ', $table_name))); echo 'Create `' . $table_name . '`...'; if (ModelHelper::importTable($table_name)) { echo 'ok' . PHP_EOL; // sync class file $class_path = CLASS_ROOT . '/model/' . $class_name . '.php'; if (file_exists($class_path)) { echo "\tClass file exists" . PHP_EOL; } else { $column_list = $db_obj->getTableColumns($table_name);
public static function syncData($table_name) { $sql_path = DATA_SQL_ROOT . '/' . $table_name . '.sql'; if (!file_exists($sql_path)) { return false; } else { // end if (!file_exists($sql_path)) $db_obj = new DatabaseAccess(); $sql = "TRUNCATE {$table_name}"; $auto_increment_result = $db_obj->query($sql); $sql = file_get_contents($sql_path); $import_result = $db_obj->query($sql); unset($db_obj); return $import_result; } // end if (!file_exists($sql_path)) else }
public function __construct() { $dao = DatabaseAccess::getInstance(); $this->dbConnection = $dao->getConnection(); }
<div class="control-group"> <label class="control-label" for="table-list">Import Table</label> <div class="controls"> <div class="span2" style="margin-left: 0;"> <input type="hidden" id="table-list" name="table_list" value="" /> <table class="table table-bordered table-condensed"> <thead> </thead> <tbody> <tr> <td><input type="checkbox" id="table-checkbox-all" /></td> <td class="span2"><strong>Table Name</strong></td> </tr> <tr><td colspan="2"></td></tr> <?php $db_obj = new DatabaseAccess(); $exist_table_array = $db_obj->getAllTables(); $new_table_array = array(); foreach (glob(TABLE_SQL_ROOT . '/*.sql') as $sql_file) { $new_table_array[] = str_replace('.sql', '', str_replace(TABLE_SQL_ROOT . '/', '', $sql_file)); } // foreach (glob(TABLE_SQL_ROOT.'/*.sql') as $sql_file) $total_table_array = array_unique(array_merge($exist_table_array, $new_table_array)); asort($total_table_array); foreach ($total_table_array as $table_name) { if (in_array($table_name, $exist_table_array)) { ?> <tr> <td></td> <td class="input-medium"> <?php echo $table_name;
$dojodir_dojox = $dojodir . "/dojox"; $trmdir = "lib/trm"; if (!file_exists($dojodir)) { echo $dojodir . "does not exist !<br>"; } if (!file_exists($dojodir_dojo)) { echo $dojodir . "does not exist !<br>"; } if (!file_exists($dojodir_dijit)) { echo $dojodir . "does not exist !<br>"; } if (!file_exists($dojodir_dojox)) { echo $dojodir . "does not exist !<br>"; } //check the db connection $dba1 = new DatabaseAccess(); if ($dba1->checkDbConnection()) { $dba1->createTableStructure(); $uf1 = new UserFactory(); if ($uf1->registerUser($username, $password, "")) { echo "user created successfully<br/>"; //try to login $usr = application_loginuser($username, $password); if ($usr != null) { $df = new DirectoryFactory(); $df->login(); if ($df->createDirectory("trf_" . $usr->getUid())) { echo "user directory created successfully<br/>"; } else { echo "<b>could not create user directory you can do it manually<br/></b>"; echo "please create a directory called: trf_" . $usr->getUid() . "<br/>";
<div class="controls"> <div class="span6" style="margin-left: 0;"> <input type="hidden" id="table-list" name="table_list" value="" /> <table class="table table-bordered table-condensed"> <thead> </thead> <tbody> <tr> <td><input type="checkbox" id="table-checkbox-all" /></td> <td class="span2"><strong>Table Name</strong></td> <td class="span2"><strong>Data Last Modified</strong></td> <td class="span2"><strong>File Last Modified</strong></td> </tr> <tr><td colspan="4"></td></tr> <?php $db_obj = new DatabaseAccess(); $exist_table_array = $db_obj->getAllTables(); foreach ($exist_table_array as $table_name) { $sql_path = DATA_SQL_ROOT . '/' . $table_name . '.sql'; $data_last_modify_time = $db_obj->getTableLastModifyTime($table_name); $file_last_modify_time = @filemtime($sql_path) ? date('Y/m/d H:i:s', filemtime($sql_path)) : '--'; $row_class = ''; $file_last_modify_time_class = ''; if ($data_last_modify_time > $file_last_modify_time) { $row_class = 'info'; $file_last_modify_time_class = 'text-error'; } // end if ($data_last_modify_time > $file_last_modify_time) ?> <tr class="<?php echo $row_class;