本文整理汇总了PHP中mysql::connect方法的典型用法代码示例。如果您正苦于以下问题:PHP mysql::connect方法的具体用法?PHP mysql::connect怎么用?PHP mysql::connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mysql
的用法示例。
在下文中一共展示了mysql::connect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Конструктор
*/
public function __construct()
{
//Получаем имя драйвера
$db = Boot::getInstance()->config->db;
$driver = $db->adapter;
$host = $db->host;
$port = $db->port;
$user = $db->user;
$pass = $db->password;
$dbase = $db->dbase;
//Инитим драйвер
$this->_db = new $driver($host, $port, $user, $pass, $dbase);
//Подключаемся к базе
$this->_db->connect();
}
示例2: __construct
private function __construct()
{
//-----------需要页面显示调试信息, 注释掉下面两行即可---
//-------------------------------------------------------
set_error_handler(array("Core", 'appError'));
set_exception_handler(array("Core", 'appException'));
date_default_timezone_set("Asia/Shanghai");
if (version_compare(PHP_VERSION, '5.4.0', '<')) {
@set_magic_quotes_runtime(0);
define('MAGIC_QUOTES_GPC', get_magic_quotes_gpc() ? True : False);
}
if (!defined('WEB_PATH')) {
//define("WEB_PATH","D:/wamp/www/pc2.valsun.cn/");
define("WEB_PATH", "/data/web/erpNew/pc.valsun.cn/");
}
include WEB_PATH . "lib/common.php";
//加载全局配置信息
C(include WEB_PATH . 'conf/common.php');
include WEB_PATH . "lib/auth.php";
//鉴权
include WEB_PATH . "lib/authuser.class.php";
//新鉴权
//Auth::setAccess(include WEB_PATH.'conf/access.php');
include WEB_PATH . "lib/log.php";
//加载数据接口层及所需支撑
include WEB_PATH . "lib/service/http.php";
//网络接口
include WEB_PATH . "lib/functions.php";
include WEB_PATH . "lib/page.php";
include WEB_PATH . "lib/template.php";
//PHPLIB 的模板类
include WEB_PATH . "lib/cache/cache.php";
//memcache
include WEB_PATH . "lib/PHPExcel.php";
//PHPExcel
//include WEB_PATH."lib/rabbitmq/rabbitmq.class.php";
//加载语言包
//$lang = WEB_PATH."lang/".C("LANG").".php"; //memcache
if (file_exists($lang)) {
//echo $lang;
//C(include $lang);
}
if (C("DATAGATE") == "db") {
$db = C("DB_TYPE");
include WEB_PATH . "lib/db/" . $db . ".php";
//db直连
if ($db == "mysql") {
global $dbConn;
$db_config = C("DB_CONFIG");
$dbConn = new mysql();
$dbConn->connect($db_config["master1"][0], $db_config["master1"][1], $db_config["master1"][2]);
$dbConn->select_db($db_config["master1"][4]);
}
if (DB_TYPE == "mongodb") {
//.......
}
}
//自动加载类
spl_autoload_register(array('Core', 'autoload'));
}
示例3: process_message
function process_message($msg)
{
echo "\n############ 信息日志开始 ###############\n";
echo date('Y-m-d H:i:s') . "=====" . $msg->body;
echo "\n############ 信息日志结束 ###############\n";
//执行SQL语句
$db_config = C("DB_CONFIG");
$dbConn = new mysql();
$dbConn->connect($db_config["master1"][0], $db_config["master1"][1], $db_config["master1"][2], '');
$dbConn->select_db($db_config["master1"][4]);
$sql = $msg->body;
$query = $dbConn->query($sql);
if (!$query) {
Log::write($sql, Log::ERR);
} else {
echo date('Y-m-d H:i:s') . '===== [ok] ', '=====', $sql, "\n";
//确认消费OK
$msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']);
}
$dbConn->close();
// Send a message with the string "quit" to cancel the consumer.
if ($msg->body === 'quit') {
$msg->delivery_info['channel']->basic_cancel($msg->delivery_info['consumer_tag']);
}
}
示例4: chk_login
public function chk_login()
{
global $db, $config, $enterprisemodel;
$r['err'] = '';
$db2 = new mysql($config["db2"]);
$db2->connect();
$query = "SELECT * FROM `{$config['db'][0]['dbname']}`.`{$config['default_prefix']}enterprise` e\r\n\t\t JOIN `{$config['db'][0]['dbname']}`.`{$config['default_prefix']}enterprise_profile` ep\r\n\t\t\t\t ON e.enterpriseid=ep.enterpriseid and e.switch='Y'\r\n\t\t WHERE e.prefixid = '{$config['default_prefix_id']}' \r\n\t\t\t AND e.loginname = '{$_POST['loginname']}' \r\n\t\t\t AND e.switch = 'Y' \r\n\t\t LIMIT 1\r\n\t\t";
error_log("[ajax/enterprise.chk_login]" . $query);
$table = $db2->getQueryRecord($query);
if (empty($table['table']['record'])) {
//'账号不存在'
$r['err'] = 3;
} else {
$_SESSION['sajamanagement']['enterprise'] = '';
$enterprise = $table['table']['record'][0];
$passwd = $this->str->strEncode($_POST['passwd'], $config['encode_key']);
if ($enterprise['passwd'] === $passwd) {
$_SESSION['sajamanagement']['enterprise'] = $enterprise;
setcookie("enterpriseid", $enterprise['enterpriseid'], time() + 43200, "/", COOKIE_DOMAIN);
$r['err'] = '';
} else {
//'密码不正确'
$r['err'] = 5;
}
}
return $r;
}
示例5: __construct
/**
* Main constructor function, used to initialize the models, connect to the DB and
* route the user to where they need to go.
*/
public function __construct()
{
global $config, $db, $tpl, $bid, $deposit, $faq, $history, $mall, $member, $product, $user, $scodeModel, $oscode, $googlemap, $channel, $enterprise;
// Connect to the database.
try {
// 初始化資料庫連結介面
$db = new mysql($config["db"]);
// 20141128 disabled by Thomas, 因為進入首頁時不須連線DB, 暫時先移除
$db->connect();
} catch (Exception $e) {
die($e);
}
// Create new models.
$tpl = new TemplateModel();
$bid = new BidModel();
$channel = new ChannelModel();
$deposit = new DepositModel();
$faq = new FaqModel();
$history = new HistoryModel();
$mall = new MallModel();
$member = new MemberModel();
$product = new ProductModel();
//var_dump($product);
$user = new UserModel();
$scodeModel = new ScodeModel();
$googlemap = new GoogleMapModel();
$enterprise = new EnterpriseModel();
$oscode = new OscodeModel();
// Figure out which controller the user is requesting and perform the correct actions.
$this->router();
}
示例6: init_db
private function init_db()
{
if ($this->is_init) {
return;
}
$db = new mysql($this->_config);
$db->connect();
DB::init($db, $this->_config['db']['tablepre']);
$this->is_init = true;
}
示例7: reconnect
function reconnect()
{
global $dbConn;
if (mysql_ping()) {
return;
}
$db_config = C("DB_CONFIG");
$dbConn = new mysql();
$dbConn->connect($db_config["master1"][0], $db_config["master1"][1], $db_config["master1"][2]);
$dbConn->select_db($db_config["master1"][4]);
}
示例8: f
public static function f($connection)
{
list($host, $user, $pass, $db) = explode(':', $connection);
if (empty(self::$instance_f[$connection])) {
$i = new mysql();
$i->connect($host, $user, $pass, $db, true);
self::$instance_f[$connection] = $i;
return $i;
} else {
return self::$instance_f[$connection];
}
}
示例9: saja
public function saja()
{
$time_start = $this->time_start;
global $db, $config, $router;
// 初始化資料庫連結介面
$db = new mysql($config["db"]);
$db->connect();
$router = $this->time_start;
$this->userid = empty($_SESSION['auth_id']) ? '' : $_SESSION['auth_id'];
$ret['status'] = 0;
$ret['winner'] = '';
$ret['rank'] = '';
//讀取商品資料
$query = "SELECT p.*, unix_timestamp(p.offtime) as offtime, unix_timestamp() as `now`\r\n\t\tFROM `{$config['db'][4]['dbname']}`.`{$config['default_prefix']}product` p \r\n\t\tWHERE \r\n\t\t\tp.prefixid = '{$config['default_prefix_id']}'\r\n\t\t\tAND p.productid = '{$_POST['productid']}'\r\n\t\t\tAND p.switch = 'Y'\r\n\t\tLIMIT 1\r\n\t\t";
$table = $db->getQueryRecord($query);
unset($table['table']['record'][0]['description']);
$product = $table['table']['record'][0];
if ($product['offtime'] == 0 && $product['locked'] == 'Y' || $product['offtime'] > 0 && $product['now'] > $product['offtime']) {
//回傳: 本商品已结标
$ret['status'] = 2;
}
/*
elseif($this->chk_time_limit() ) {
//回傳: 下标时间间隔过短,请稍后再下标
$ret['status'] = 3;
}*/
if ($_POST['type'] == 'single') {
//單次下標
$chk = $this->chk_single($product);
if ($chk['err']) {
$ret['status'] = $chk['err'];
}
} elseif ($_POST['type'] == 'range') {
//連續下標
$chk = $this->chk_range($product);
if ($chk['err']) {
$ret['status'] = $chk['err'];
}
}
if (empty($ret['status'])) {
//產生下標歷史記錄
$mk = $this->mk_history($product);
//回傳: 下标完成
$ret['status'] = $mk['err'] ? $mk['err'] : 200;
$ret['winner'] = $mk['winner'];
$ret['rank'] = $mk['rank'];
}
$time_end = microtime(true);
$time = number_format($time_end - $time_start, 10);
echo "下標 {$time} 秒<br>";
echo json_encode($ret);
}
示例10: get_country
/**
* Country Method : get_country
*/
public function get_country()
{
// global $db, $config;
global $config;
$db = new mysql($config["db2"]);
$db->connect();
$query = "SELECT *\n\t\tFROM `{$config['db'][2]['dbname']}`.`{$config['default_prefix']}country` \n\t\tWHERE\n\t\t\tprefixid = '{$config['default_prefix_id']}'\n\t\t\tAND switch = 'Y'\n\t\t\tORDER BY countryid\n\t\t";
$table = $db->getQueryRecord($query);
if (!empty($table['table']['record'])) {
return $table['table']['record'];
}
return false;
}
示例11: _checkJsapiTicket
/**
* @descrpition 检测微信ACCESS_TOKEN是否过期
* -10是预留的网络延迟时间
* @return bool
*/
private static function _checkJsapiTicket()
{
//获取access_token。是上面的获取方法获取到后存起来的。
$db = new mysql();
$db->connect(DBHOST, DBUSER, DBPASSWORD, DBNAME);
$tempJsapiTicket = $db->fetch_first("select * from jsapiticket");
$JsapiTicket['value'] = $tempJsapiTicket['ticket'];
if (!empty($JsapiTicket['value'])) {
$JsapiTicket = json_decode($JsapiTicket['value'], true);
if (time() - $JsapiTicket['time'] < $JsapiTicket['expires_in'] - 20) {
return $JsapiTicket;
}
}
return false;
}
示例12: _checkAccessToken
/**
* @descrpition 检测微信ACCESS_TOKEN是否过期
* -10是预留的网络延迟时间
* @return bool
*/
private static function _checkAccessToken()
{
//获取access_token。是上面的获取方法获取到后存起来的。
$db = new mysql();
$db->connect(DBHOST, DBUSER, DBPASSWORD, DBNAME);
$tempaccessToken = $db->fetch_first("select * from accesstoken");
$accessToken['value'] = $tempaccessToken['access_token'];
if (!empty($accessToken['value'])) {
$accessToken = json_decode($accessToken['value'], true);
if (time() - $accessToken['time'] < $accessToken['expires_in'] - 10) {
return $accessToken;
}
}
return false;
}
示例13: home
public function home()
{
global $db, $config, $router;
// 初始化資料庫連結介面
$db = new mysql($config["db"]);
$db->connect();
$router = new Router();
$this->userid = empty($_SESSION['auth_id']) ? '' : $_SESSION['auth_id'];
$ret['status'] = 0;
// Check Variable Start
if (empty($_GET['pgpid'])) {
$ret['status'] = 0;
} elseif (empty($_POST['name'])) {
//('收件人姓名错误!!');
$ret['status'] = 2;
} elseif (empty($_POST['zip'])) {
//('收件人邮编错误!!');
$ret['status'] = 3;
} elseif (empty($_POST['address'])) {
//('收件人地址错误!!');
$ret['status'] = 4;
} else {
$query = "SELECT p.*, unix_timestamp(offtime) as offtime, unix_timestamp() as `now`, pgp.pgpid, pgp.price, pgp.complete \r\n\t\t\tFROM `{$config['db'][4]['dbname']}`.`{$config['default_prefix']}pay_get_product` pgp \r\n\t\t\tLEFT OUTER JOIN `{$config['db'][4]['dbname']}`.`{$config['default_prefix']}product` p ON \r\n\t\t\t\tpgp.prefixid = p.prefixid\r\n\t\t\t\tAND pgp.productid = p.productid\r\n\t\t\t\tAND p.switch = 'Y' \r\n\t\t\tWHERE \r\n\t\t\t\tpgp.`prefixid` = '{$config['default_prefix_id']}' \r\n\t\t\t\tAND pgp.pgpid = '{$_GET["pgpid"]}'\r\n\t\t\t\tAND pgp.userid = '{$this->userid}'\r\n\t\t\t\tAND pgp.switch = 'Y'\r\n\t\t\t";
$table = $db->getQueryRecord($query);
//if (empty($table['table']['record'])) { $this->jsPrintMsg('商品不存在!', $location_url); }
$product = $table['table']['record'][0];
$product['price'] = round($product['price'] * $config['sjb_rate'], 2);
$product['real_process_fee'] = round($product['retail_price'] * $product['process_fee'] / 100 * $config['sjb_rate'], 2);
$product['total'] = $product['real_process_fee'] + $product['price'];
$query = "select sum(amount) as total_amount\r\n\t\t\tfrom `{$config['db'][1]['dbname']}`.`{$config['default_prefix']}spoint` \r\n\t\t\twhere\r\n\t\t\t\tuserid = '{$this->userid}'\r\n\t\t\t\tand switch = 'Y'\r\n\t\t\tGROUP BY userid\r\n\t\t\t";
$table = $db->getQueryRecord($query);
if ($table['table']['record'][0]['total_amount'] < $product['total']) {
//餘額不足
$ret['status'] = 6;
}
if ($product['complete'] == 'Y') {
//'已结账'
$ret['status'] = 5;
}
}
if (empty($ret['status'])) {
//產生訂單記錄
$mk = $this->mk_order($product);
//回傳: 完成
$ret['status'] = $mk['err'] ? $mk['err'] : 200;
}
echo json_encode($ret);
}
示例14: faq_detail
public function faq_detail($id)
{
// global $db, $config;
global $config;
$db = new mysql($config["db2"]);
$db->connect();
$query = "SELECT f.*, fc.name cname\n\t\tFROM `{$config["db"][0]["dbname"]}`.`{$config['default_prefix']}faq` f \n\t\tLEFT OUTER JOIN `{$config["db"][0]["dbname"]}`.`{$config['default_prefix']}faq_category` fc ON \n\t\t\tf.prefixid = fc.prefixid \n\t\t\tAND f.fcid = fc.fcid \n\t\t\tAND fc.`switch`='Y' \n\t\tWHERE \n\t\t\tf.prefixid = '{$config["default_prefix_id"]}' \n\t\t\tAND f.faqid ='{$id}' \n\t\t\tAND f.switch = 'Y'\n\t\t";
$table = $db->getQueryRecord($query);
if (!empty($table['table']['record'][0])) {
//简介
$description = !empty($table['table']['record'][0]['description']) ? $table['table']['record'][0]['description'] : '空白';
$table['table']['record'][0]['description'] = html_decode($description);
return $table['table']['record'][0];
}
return false;
}
示例15: step3
function step3($data)
{
if (!isset($_POST['host']) || !isset($_POST['username']) || !isset($_POST['password']) || !isset($_POST['database']) || !isset($_POST['adress'])) {
return "Es trat ein Fehler bei der �rmittlung der Daten auf.";
}
$mysql = new mysql(array());
if (!@$mysql->connect($_POST['host'], $_POST['username'], $_POST['password'])) {
return "Es konnte keine Verbindung zum Server hergestellt werden.<br />Überprüfe bitte deine Angaben auf ihre Richtigkeit.<br />" . mysql_error();
}
if (!@$mysql->select_db($_POST['database'])) {
return "Die gewünschte Datenbank konnte nicht ausgewählt werden.<br />Entweder existiert diese nicht oder der gewählte Benutzer hat keine Zugriffsrechte.<br />" . mysql_error();
}
$_SESSION['install']['mysql']['host'] = $_POST['host'];
$_SESSION['install']['mysql']['username'] = $_POST['username'];
$_SESSION['install']['mysql']['password'] = $_POST['password'];
$_SESSION['install']['mysql']['database'] = $_POST['database'];
$_SESSION['install']['tic_adress'] = $_POST['adress'];
$tables = array("gn4accounts", "gn4allianzen", "gn4cron", "gn4flottenbewegungen", "gn4forum", "gn4gnuser", "gn4incplanets", "gn4log", "gn4nachrichten", "gn4nachtwache", "gn4meta", "gn4scans", "gn4attflotten", "gn4attplanung", "gn4vars", "gn4channels");
$mysql->query("SHOW TABLE STATUS") or die($mysql->error(__FILE__, __LINE__));
$tableexits = array();
while ($row = $mysql->fetch()) {
$tableexits[$row['Name']] = 1;
}
echo "<div style=\"border:1px #000000 solid;width:400px;padding:3px;\"><b>Schritt 3: Überprüfe Tabellen</b>\n <form action=\"\" method=\"post\"><input type=\"hidden\" name=\"step\" value=\"4\" \\>\n <table style=\"text-align:left;\" cellspacing=\"0\" cellpadding=\"0\">\n <tr style=\"font-weight:bold;\"><td>Tabellenname</td><td>Installieren</td></tr>";
$showwarning = 0;
foreach ($tables as $table) {
if ($tableexits[$table]) {
$color = "#800000";
$showwarning = 1;
$input = "<input type=\"checkbox\" name=\"check[]\" value=\"" . $table . "\" checked=\"checked\"/>";
} else {
$color = "#008000";
$input = "<input type=\"checkbox\" checked=\"checked\" disabled = \"disabled\" /><input type=\"hidden\" name=\"check[]\" value=\"" . $table . "\" />";
}
echo "<tr style=\"color:" . $color . "\"><td>{$table}</td><td style=\"text-align:center\">" . $input . "</td></tr>";
}
if ($showwarning) {
echo "</table><br /><div style=\"text-align:left\"><b>ACHTUNG:</b> Rot makierte Tabellen existieren bereits und werden, sofern die Installation fortgesetzt wird, inklusive ihrer Daten berschrieben.</div>";
}
echo "<input type=\"submit\" value=\"Weiter\" /></form>\n </div>";
return "";
}