本文整理汇总了PHP中Database::connect方法的典型用法代码示例。如果您正苦于以下问题:PHP Database::connect方法的具体用法?PHP Database::connect怎么用?PHP Database::connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Database
的用法示例。
在下文中一共展示了Database::connect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getEquip
function getEquip()
{
$db = new Database();
$link = $db->connect();
$result = $db->select($link, 'equip_type');
return $result;
}
示例2: __construct
public function __construct()
{
$this->db = new Database();
$this->gm = new GroupMeService('birthday');
$this->db->connect();
$this->process();
}
示例3: initDatabase
/**
* Initialise a database connection.
* @param $type
* @param $hostname
* @param $database
* @param $username
* @param $password
* @return bool
* @throws \Exception
*/
protected function initDatabase($type, $hostname, $database, $username, $password)
{
$className = "DBtrack\\Databases\\{$type}";
if (!class_exists($className)) {
throw new \Exception('Unsupported database type: ' . $type);
}
$this->dbms = new $className($hostname, $database, $username, $password);
return $this->dbms->connect();
}
示例4: main
function main()
{
$program_start_time = microtime(true);
$arguments = validate_arguments($_GET, array('platform' => 'int', 'metric' => 'int', 'testGroup' => 'int?', 'startTime' => 'int?', 'endTime' => 'int?'));
$platform_id = $arguments['platform'];
$metric_id = $arguments['metric'];
$start_time = $arguments['startTime'];
$end_time = $arguments['endTime'];
if (!!$start_time != !!$end_time) {
exit_with_error('InvalidTimeRange', array('startTime' => $start_time, 'endTime' => $end_time));
}
$db = new Database();
if (!$db->connect()) {
exit_with_error('DatabaseConnectionFailure');
}
$fetcher = new MeasurementSetFetcher($db);
if (!$fetcher->fetch_config_list($platform_id, $metric_id)) {
exit_with_error('ConfigurationNotFound', array('platform' => $platform_id, 'metric' => $metric_id));
}
$cluster_count = 0;
while (!$fetcher->at_end()) {
$content = $fetcher->fetch_next_cluster();
$cluster_count++;
if ($fetcher->at_end()) {
$cache_filename = "measurement-set-{$platform_id}-{$metric_id}.json";
$content['clusterCount'] = $cluster_count;
$content['elapsedTime'] = (microtime(true) - $program_start_time) * 1000;
} else {
$cache_filename = "measurement-set-{$platform_id}-{$metric_id}-{$content['endTime']}.json";
}
$json = success_json($content);
generate_data_file($cache_filename, $json);
}
echo $json;
}
示例5: Site
/**
* Site constructor
*
* Given all the settings values from the config file, the function sets
* the values to all its settings preferences, on construct.
*
* It also starts the benchmarking process, prepares the emoticon variables
* (using the emoticons.cfg), and then starts the Smarty service.
*
* @return void
* @param string $configfile location of config settings .ini file
*/
function Site($configfile)
{
$this->startBenchmark();
$this->config = $this->fetchConfig($configfile);
$this->db = new Database($this->config['database']['hostname'], $this->config['database']['username'], $this->config['database']['password'], $this->config['database']['name'], $this->config['database']['prefix']);
$dbc = $this->db->connect();
if ($dbc !== TRUE) {
$this->displayError('$site->Site', $dbc);
}
$this->name = $this->config['website']['name'];
$this->title = $this->config['website']['title'];
$this->slogan = $this->config['website']['slogan'];
$this->url = $this->config['website']['url'];
$this->path = $this->config['website']['path'];
$this->theme = $this->config['website']['theme'];
$this->webmaster = $this->config['webmaster']['name'];
$this->email = $this->config['webmaster']['email'];
$this->ad_pass = $this->config['admin']['password'];
$this->prepareEmoticons();
$this->smarty = new Smarty();
// smarty directories
$this->smarty->template_dir = 'templates/' . $this->theme;
$this->smarty->compile_dir = 'templates_c';
$this->smarty->config_dir = 'configs';
$this->smarty->cache_dir = 'cache';
// custom modifiers & functions
/* my plugins: * modifier.linkalize.php
* modifier.autop.php
* modifier.hebdate.php
* modifier.n0tags.php
* function.mymailto.php */
}
示例6: rpc_post_install
public static function rpc_post_install(Context $ctx)
{
$data = $ctx->post;
if (empty($data['dbtype'])) {
throw new RuntimeException(t('Вы не выбрали тип БД.'));
}
$config = $ctx->config;
// Выносим секцию main в самое начало.
$config['main'] = array();
if ($config->isok()) {
throw new ForbiddenException(t('Инсталляция невозможна: конфигурационный файл уже есть.'));
}
$dsn = self::getDSN($data['dbtype'], $data['db'][$data['dbtype']]);
if (!empty($data['db']['prefix'])) {
$dsn['prefix'] = $data['db']['prefix'];
}
$config->set('modules/db', $dsn);
foreach (array('modules/mail/server', 'modules/mail/from', 'main/debug/errors') as $key) {
if (!empty($data[$key])) {
$config->set($key, $data[$key]);
}
}
$config->set('modules/files/storage', 'files');
$config->set('modules/files/ftp', 'ftp');
$config->set('main/tmpdir', 'tmp');
$config->set('main/debug/allow', array('127.0.0.1', $_SERVER['REMOTE_ADDR']));
// Создаём маршрут для главной страницы.
$config['routes']['localhost/'] = array('title' => 'Molinos CMS', 'theme' => 'example', 'call' => 'BaseRoute::serve');
// Проверим соединение с БД.
$pdo = Database::connect($config->get('modules/db'));
// Подключились, можно сохранять конфиг.
$config->save();
$ctx->redirect('admin/system/reload?destination=admin/system/settings');
}
示例7: __construct
function __construct()
{
if (!is_a($this->mysqli, "MySQLi")) {
$this->mysqli = Database::connect();
}
$this->initialize();
}
示例8: allusers
public function allusers($title, $body)
{
// To send HTML mail, the Content-type header must be set
$header = 'MIME-Version: 1.0' . "\r\n";
$header .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$header .= 'From: register@domain.com' . "\r\n";
$header .= 'Reply-To: register@domain.com' . "\r\n";
$header .= 'X-Mailer: PHP/' . phpversion();
$message = "<html>";
$message .= "<body>";
$message .= $body;
$message .= "</body>";
$message .= "</html>";
//echo $message;
$db = new Database();
$db->connect();
$query = "select `email` from `user` where `accountstatusid`>1";
$db->query($query);
$tmp = $db->getresult();
foreach ($tmp as $value) {
//echo "mail(".$value['email'].")<br>";
mail($value['email'], $title, $message, $header);
}
//mail('jeff@domain.com',$title,$message,$header);
}
示例9: count_members
private function count_members()
{
$query = "SELECT COUNT(*) AS num_of_members FROM members WHERE individual_headhunter = 'Y'";
$mysql = Database::connect();
$result = $mysql->query($query);
return $result[0]['num_of_members'];
}
示例10: __construct
function __construct($_id = "", $_seed_id = "")
{
if (!is_a($this->mysqli, "MySQLi")) {
$this->mysqli = Database::connect();
}
$this->initializeWith($_id, $_seed_id);
}
示例11: main
function main($path)
{
if (count($path) > 1) {
exit_with_error('InvalidRequest');
}
$db = new Database();
if (!$db->connect()) {
exit_with_error('DatabaseConnectionFailure');
}
$task_id = array_get($_GET, 'task');
$query = array();
if ($task_id) {
$triggerable = find_triggerable_for_task($db, $task_id);
if (!$triggerable) {
exit_with_error('TriggerableNotFoundForTask', array('task' => $task_id));
}
$query['id'] = $triggerable['id'];
}
$id_to_triggerable = array();
foreach ($db->select_rows('build_triggerables', 'triggerable', $query) as $row) {
$id = $row['triggerable_id'];
$repositories = array();
$id_to_triggerable[$id] = array('id' => $id, 'name' => $row['triggerable_name'], 'acceptedRepositories' => &$repositories);
}
foreach ($db->select_rows('triggerable_repositories', 'trigrepo', array()) as $row) {
$triggerable = array_get($id_to_triggerable, $row['trigrepo_triggerable']);
if ($triggerable) {
array_push($triggerable['acceptedRepositories'], $row['trigrepo_repository']);
}
}
exit_with_success(array('triggerables' => array_values($id_to_triggerable)));
}
示例12: main
function main($post_data)
{
set_exit_detail('failureStored', false);
$db = new Database();
if (!$db->connect()) {
exit_with_error('DatabaseConnectionFailure');
}
// Convert all floating points to strings to avoid parsing them in PHP.
// FIXME: Do this conversion in the submission scripts themselves.
$parsed_json = json_decode(preg_replace('/(?<=[\\s,\\[])(\\d+(\\.\\d+)?)(\\s*[,\\]])/', '"$1"$3', $post_data), true);
if (!$parsed_json) {
exit_with_error('FailedToParseJSON');
}
set_exit_detail('processedRuns', 0);
foreach ($parsed_json as $i => $report) {
$processor = new ReportProcessor($db);
$processor->process($report);
set_exit_detail('processedRuns', $i + 1);
}
$generator = new ManifestGenerator($db);
if (!$generator->generate()) {
exit_with_error('FailedToGenerateManifest');
} else {
if (!$generator->store()) {
exit_with_error('FailedToStoreManifest');
}
}
exit_with_success();
}
示例13: validateDatabase
protected function validateDatabase($e)
{
if (!extension_loaded('pdo')) {
$e->add($this->getDBErrorMsg());
} else {
// attempt to connect to the database
if (defined('DB_SERVER')) {
$db = DB::connect(array('host' => DB_SERVER, 'user' => DB_USERNAME, 'password' => DB_PASSWORD, 'database' => DB_DATABASE));
$DB_SERVER = DB_SERVER;
$DB_DATABASE = DB_DATABASE;
} else {
$db = DB::connect(array('host' => $_POST['DB_SERVER'], 'user' => $_POST['DB_USERNAME'], 'password' => $_POST['DB_PASSWORD'], 'database' => $_POST['DB_DATABASE']));
$DB_SERVER = $_POST['DB_SERVER'];
$DB_DATABASE = $_POST['DB_DATABASE'];
}
if ($DB_SERVER && $DB_DATABASE) {
if (!$db) {
$e->add(t('Unable to connect to database.'));
} else {
$num = $db->GetCol("show tables");
if (count($num) > 0) {
$e->add(t('There are already %s tables in this database. concrete5 must be installed in an empty database.', count($num)));
}
}
}
}
return $e;
}
示例14: update_comment
public static function update_comment()
{
$sql_query = "UPDATE `comments` SET `comment` = 'This is a Test Mannnnn hehheeh' WHERE `id` = '2'";
$pdo = Database::connect();
$pdo->query($sql_query);
Database::disconnect();
}
示例15: check_complete
/**
* @param $job_id
* @return bool|mysqli_result
*/
public function check_complete($job_id)
{
//makes a request for verification Field work performed
//db_connect() method extends from class Database
$query = mysqli_query(Database::connect(), "SELECT job_done FROM family_job WHERE id='" . $job_id . "'") or die(mysqli_error(Database::connect()));
return $query;
}