本文整理汇总了PHP中MySQL::connect方法的典型用法代码示例。如果您正苦于以下问题:PHP MySQL::connect方法的具体用法?PHP MySQL::connect怎么用?PHP MySQL::connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MySQL
的用法示例。
在下文中一共展示了MySQL::connect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parseFile
function parseFile($file, $type)
{
$sql = new MySQL();
$sql->connect('127.0.0.1', 'root', 'root');
$objReader = PHPExcel_IOFactory::createReader($type);
$chunkSize = 200;
$i = 1;
$sql->clear('price_liga');
$r = array();
for ($startRow = 0; $startRow <= 5000; $startRow += $chunkSize + 1) {
$chunkFilter = new chunkReadFilter($startRow, $chunkSize);
$objReader->setReadFilter($chunkFilter);
$objReader->setReadDataOnly(true);
$objPHPExcel = $objReader->load($file);
$data = $objPHPExcel->getActiveSheet()->toArray();
foreach ($data as $k => $v) {
if ($data[$k][0] == '') {
unset($data[$k]);
} else {
$sql->insert('price_liga', array('id' => $i, 'cat_num' => $data[$k][0], 'brand' => ucwords(strtolower($data[$k][1])), 'article' => $data[$k][2], 'descr' => str_replace("'", "\\'", $data[$k][3]), 'model' => str_replace("'", "\\'", $data[$k][4]), 'size' => $data[$k][5], 'price' => $data[$k][6], 'amount' => $data[$k][8]), true);
$i++;
}
}
}
//print_r($r);
$sql->close();
return array('counter' => $i);
}
示例2: initialiseDatabase
/**
* Setter for the `$Database`. This will create a new Database driver
* and then attempt to create a connection to the database using the
* connection details provided in the Symphony configuration. If any
* errors occur whilst doing so, a Symphony Error Page is displayed.
*
* @return boolean
* This function will return true if the `$Database` was
* initialised successfully.
*/
public function initialiseDatabase()
{
if (self::$Database) {
return true;
}
self::$Database = new MySQL();
$details = self::$Configuration->get('database');
try {
if (!self::$Database->connect($details['host'], $details['user'], $details['password'], $details['port'], $details['db'])) {
return false;
}
if (!self::$Database->isConnected()) {
return false;
}
self::$Database->setPrefix($details['tbl_prefix']);
if (self::$Configuration->get('runtime_character_set_alter', 'database') == '1') {
self::$Database->setCharacterEncoding(self::$Configuration->get('character_encoding', 'database'));
self::$Database->setCharacterSet(self::$Configuration->get('character_set', 'database'));
}
if (self::$Configuration->get('query_caching', 'database') == 'off') {
self::$Database->disableCaching();
} elseif (self::$Configuration->get('query_caching', 'database') == 'on') {
self::$Database->enableCaching();
}
} catch (DatabaseException $e) {
$error = self::$Database->getlastError();
throw new SymphonyErrorPage($error['num'] . ': ' . $error['msg'], 'Symphony Database Error', 'database-error', array('error' => $error, 'message' => __('There was a problem whilst attempting to establish a database connection. Please check all connection information is correct. The following error was returned.')));
}
return true;
}
示例3: __construct
public function __construct($login, $senha)
{
parent::connect();
$this->_fields['NMLOGIN'] = $login;
$this->_fields['CDSENHA'] = $senha;
$this->_Error = new Error();
}
示例4: parseFile
function parseFile($file, $type)
{
$sql = new MySQL();
$sql->connect('127.0.0.1', 'root', 'root');
$objReader = PHPExcel_IOFactory::createReader($type);
$chunkSize = 200;
$i = 1;
$sql->clear('price_v8');
for ($startRow = 0; $startRow <= 5000; $startRow += $chunkSize + 1) {
$chunkFilter = new chunkReadFilter($startRow, $chunkSize);
$objReader->setReadFilter($chunkFilter);
$objReader->setReadDataOnly(true);
$objPHPExcel = $objReader->load($file);
$data = $objPHPExcel->getActiveSheet()->toArray();
foreach ($data as $k => $v) {
if (trim($data[$k][0]) == 'Артикул' || $data[$k][3] == '' || strstr($data[$k][3], 'камера') || $data[$k][7] == '') {
unset($data[$k]);
} else {
$descr = str_replace('Ш', 'xSTUDEDx', trim($data[$k][3]));
$descr = preg_replace('/[а-яА-Я]/', '', $descr);
$sql->insert('price_v8', array('id' => $i, 'article' => trim($data[$k][0]), 'descr' => str_replace("'", "\\'", $descr), 'cat_num' => trim($data[$k][6]), 'season' => trim($data[$k][7]), 'price' => trim($data[$k][9]), 'amount' => trim(preg_replace('/[а-яА-Яa-zA-Z]{0,}/', '', $data[$k][10]))), true);
$i++;
}
}
}
$sql->close();
return array('counter' => $i);
}
示例5: testDatabaseConnection
/**
* Tests that this adapter can connect to the database, and that the status is properly
* persisted.
*
* @return void
*/
public function testDatabaseConnection()
{
$db = new MySql(array('autoConnect' => false) + $this->_dbConfig);
$this->assertTrue($db->connect());
$this->assertTrue($db->isConnected());
$this->assertTrue($db->disconnect());
$this->assertFalse($db->isConnected());
$db = new MySQL(array('autoConnect' => false, 'encoding' => NULL, 'persistent' => false, 'host' => 'localhost:3306', 'login' => 'garbage', 'password' => '', 'database' => 'garbage', 'init' => true) + $this->_dbConfig);
$this->assertFalse($db->connect());
$this->assertFalse($db->isConnected());
$this->assertTrue($db->disconnect());
$this->assertFalse($db->isConnected());
}
示例6: parseFile
function parseFile($file, $type)
{
$sql = new MySQL();
$sql->connect('127.0.0.1', 'root', 'root');
$objReader = PHPExcel_IOFactory::createReader($type);
$sheets = $objReader->listWorksheetNames($file);
$i = 1;
$sql->clear('price_moscow');
foreach ($sheets as $sheet) {
$chunkSize = 200;
if (strstr($sheet, 'Шины')) {
$r = array();
for ($startRow = 0; $startRow <= 4000; $startRow += $chunkSize + 1) {
$chunkFilter = new chunkReadFilter($startRow, $chunkSize);
$objReader->setReadFilter($chunkFilter);
$objReader->setReadDataOnly(true);
$objReader->setLoadSheetsOnly($sheet);
$objPHPExcel = $objReader->load($file);
$data = $objPHPExcel->getActiveSheet()->toArray();
foreach ($data as $k => $v) {
if ($data[$k][2] == '' || $data[$k][2] == 'Модель') {
unset($data[$k]);
} else {
$season = strstr($data[$k][7], 'Летняя') ? 0 : (strstr($data[$k][7], 'Зимняя') ? 1 : 2);
$vtype = strstr($data[$k][8], 'Легковая') ? 0 : (strstr($data[$k][8], 'Грузовая') ? 1 : 2);
$stunds = $data[$k][10] == '' || $data[$k][10] == 'Нет' ? 0 : 1;
$xl = $data[$k][12] == '' || $data[$k][12] == 'Нет' ? 0 : 1;
$runflat = $data[$k][13] == '' || $data[$k][13] == 'Нет' ? 0 : 1;
$sql->insert('price_moscow', array('id' => $i, 'article' => trim($data[$k][0]), 'brand' => ucwords(strtolower(trim($data[$k][1]))), 'model' => str_replace("'", "\\'", trim($data[$k][2])), 'width' => trim($data[$k][3]), 'height' => trim($data[$k][4]), 'diameter' => (int) preg_replace('/[a-zA-Z]/', '', trim($data[$k][5])), 'weight_speed' => trim($data[$k][6]), 'season' => $season, 'v_type' => $vtype, 'studs' => $stunds, 'xl' => $xl, 'runflat' => $runflat, 'price_rrc' => $data[$k][17], 'price_opt' => $data[$k][18], 'amount' => 0), true);
$i++;
}
}
}
}
}
$sql->close();
return array('counter' => $i);
}
示例7: EditTeam
function EditTeam($inTeamId, $inSportId = null, $inTeamName = null, $inCoachId = null, $inSubCoachIds = null)
{
$db = new MySQL("localhost", "root", "n4UVFpHeHr", "bulilit");
$db->connect();
$teams = GetTeam($inTeamId);
$coaches;
foreach ($teams as $team) {
$coaches = $team->coachIds;
}
if ($coaches == null) {
AddTeamHeadCoach($inTeamId, $inCoachId);
} else {
$query = $db->query("UPDATE TeamCoach SET HeadCoach='Yes' WHERE TeamID=" . $inTeamId . " and CoachID=" . $inCoachId . "") or die("Error updating team Head Coach");
}
if ($coaches == null) {
AddTeamSubCoaches($inTeamId, $inSubCoachIds);
} else {
foreach ($inSubCoachIds as $s) {
$query = $db->query("UPDATE TeamCoach SET HeadCoach='No' WHERE TeamID=" . $inTeamId . " and CoachID=" . $s . "") or die("Error updating team Assistant Coaches");
}
}
$query = $db->query("UPDATE Team SET SportID=" . $inSportId . ", TeamName='" . $inTeamName . "' WHERE TeamID=" . $inTeamId) or die("Error updating team name");
}
示例8: MySQL
* Date: 08.02.2016
* Time: 13:51
*/
// Подключение к базе данных;
require_once $_SERVER['DOCUMENT_ROOT'] . '/systems/connect.php';
// Проверяем роли;
check_role(basename($_SERVER['SCRIPT_NAME'], ".php"));
if (count($_POST) == 0 && count($_GET) == 0) {
$html = '';
// Заголовок страницы;
$html .= $elements->title(basename($_SERVER['SCRIPT_NAME'], ".php"));
// Создаем объекты для подключения в базам с репликацией;
$db_replica1 = new MySQL();
$db_replica1->connect('192.168.7.8', 'mysql', 'root', 'xfFMC85ty16R4iHZS3))J');
$db_replica2 = new MySQL();
$db_replica2->connect('192.168.168.165', 'mysql', 'root', 'xfFMC85ty16R4iHZS3))J');
// Запрашиваем данные и там и там;
$replica_data_1 = $db_replica1->row('SHOW SLAVE STATUS');
$replica_data_2 = $db_replica2->row('SHOW SLAVE STATUS');
$html .= '<table>';
$html .= '<tr>';
$html .= '<td class="row_top">Сервер</td>';
$html .= '<td class="row_top inf_row">Текущее состояние</td>';
$html .= '<td class="row_top inf_row">Запущена ли репликация</td>';
$html .= '<td class="row_top inf_row">Последняя ошибка</td>';
$html .= '</tr>';
$html .= '<tr>';
$html .= '<td class="row_1" align="center">192.168.7.8</td>';
$html .= '<td class="row_1 inf_row" align="center">' . $replica_data_1['Slave_IO_State'] . '</td>';
$html .= '<td class="row_1 inf_row" align="center">' . $replica_data_1['Slave_IO_Running'] . ' / ' . $replica_data_1['Slave_SQL_Running'] . '</td>';
$html .= '<td class="row_1 inf_row" align="center">' . $replica_data_1['Last_SQL_Errno'] . ' / ' . $replica_data_1['Last_SQL_Error'] . '</td>';
示例9: ParentReply
<?php
// Подхватываем сессию главной страницы для получения ID пользователя работающего в сессии;
session_start();
// Подключение основных функций;
include $_SERVER['DOCUMENT_ROOT'] . '/systems/image_content.php';
// Подключение к базе данных;
include $_SERVER['DOCUMENT_ROOT'] . '/systems/connect.php';
// Создание объекта MySQL;
$db_shop = new MySQL();
$db_shop->connect($db_shop_host, $db_shop_name, $db_shop_user, $db_shop_password);
// Путь к временному хранилищу фотографий;
$path = '../files/uploads/';
// Функция ответа родительской страницы загрузки файлов
function ParentReply($val)
{
// Формируем js-файл информирующего о загрузке файла;
$res = '<script type="text/javascript">';
$res .= "var data = new Object;";
foreach ($val as $key => $value) {
$res .= 'data.' . $key . ' = "' . $value . '";';
}
$res .= 'window.parent.handleResponse(data);';
$res .= "</script>";
echo $res;
}
// Функция создание иотображения превьющек для фотографий;
function ThumbMaker()
{
global $path;
// Создаем массив с которым будем работать;
示例10: create_user_element
<?php
// Подключение настроек;
include $_SERVER['DOCUMENT_ROOT'] . '/config.php';
// Подключение библиотеки MySQL;
include $_SERVER['DOCUMENT_ROOT'] . '/systems/mysql.php';
// Создание объекта MySQL;
$db = new MySQL();
$db->connect($db_host, $db_name, $db_user, $db_password);
$db_inproject = new MySQL();
$db_inproject->connect($db_inproject_host, $db_inproject_name, $db_inproject_user, $db_inproject_password);
// Кодировка;
$db->query("SET NAMES `UTF8`");
// Часовой пояс;
$db->query("SET TIME_ZONE='+06:00'");
// Кодировка;
$db_inproject->query("SET NAMES `UTF8`");
// Часовой пояс;
$db_inproject->query("SET TIME_ZONE='+06:00'");
// Функцию подключения базов элементов к рабочему столу;
function create_user_element($element_id = '')
{
global $db_inproject;
$result = '';
$symbol = "'";
$sql = "SELECT `elements`.`id` AS `id`, `elements_types`.`type_name` AS `type_name`, `elements`.`name` AS `name`, `elements`.`option` AS `option` FROM `elements`, `elements_types` WHERE `elements`.`type_id` = `elements_types`.`id` AND `elements`.`user_id` = '" . $_SESSION['user_session_login'] . "' " . ($element_id != '' ? 'AND `elements`.`id` = ' . $element_id : '') . ";";
$user_elements = $db_inproject->all($sql);
foreach ($user_elements as $elements) {
// Грузим параметры каждого элемента и создаем его на рабочем столе;
$sql = "SELECT * FROM `elements_position` WHERE `element_id` = '" . $elements['id'] . "';";
$element_pos = $db_inproject->row($sql);
示例11: MySQL
<?php
include "class/class.MySQL.php";
$mySQL = new MySQL();
$mySQL->connect();
示例12: get_modem
// Определение свободного модема;
function get_modem()
{
$modem_id = 1101;
return $modem_id;
}
// Создание объекта MySQL;
$db = new MySQL();
$db->connect($db_host, $db_name, $db_user, $db_password);
// Кодировка;
$db->query("SET NAMES `UTF8`");
// Часовой пояс;
$db->query("SET TIME_ZONE='+06:00'");
// Создание объекта MySQL;
$db_site = new MySQL();
$db_site->connect($db_site_host, $db_site_name, $db_site_user, $db_site_password);
// Кодировка;
$db_site->query("SET NAMES `UTF8`");
// Часовой пояс;
$db_site->query("SET TIME_ZONE='+06:00'");
// Счетчики;
$count_payments = 0;
$count_actions = 0;
$count_messages = 0;
$count_goods_delete = 0;
$count_actions_delete = 0;
$count_companies_delete = 0;
$count_money = 0;
// Срок действия акции;
$_date = date("d.m.Y", mktime(0, 0, 0, date("n"), date("j") + 14));
$_date_real = date("Y-m-d H:i:s", mktime(0, 0, 0, date("n"), date("j") + 28));
示例13: MySQL
<?php
// Подключение настроек;
include $_SERVER['DOCUMENT_ROOT'] . '/config.php';
// Подключение библиотеки MySQL;
include $_SERVER['DOCUMENT_ROOT'] . '/systems/mysql.php';
// Создание объекта MySQL;
$db = new MySQL();
$db->connect(isset($db_localhost_force) ? $db_localhost : $db_host, $db_name, $db_user, $db_password);
// Кодировка;
$db->query("SET NAMES `UTF8`");
// Часовой пояс;
$db->query("SET TIME_ZONE='+06:00'");
// Загрузка параметров;
$sql = "CALL options()";
$options = $db->assoc($sql);
// Загрузка локальных параметров;
if (isset($options_club_id)) {
$options['club_id'] = $options_club_id;
}
if (isset($options_cash_id)) {
$options['cash_id'] = $options_cash_id;
}
if (isset($_COOKIE['club_id'])) {
$options['club_id'] = $_COOKIE['club_id'];
}
if (isset($_COOKIE['cash_id'])) {
$options['cash_id'] = $_COOKIE['cash_id'];
}
// Проверка параметров;
if (isset($_GET['terminal_id'])) {
示例14: MySQL
<?php
// Подключение настроек;
include $_SERVER['DOCUMENT_ROOT'] . '/config.php';
// Подключение библиотеки MySQL;
include $_SERVER['DOCUMENT_ROOT'] . '/mysql.php';
// Создание объекта MySQL;
$db = new MySQL();
$db->connect($db_host, $db_name, $db_user, $db_password);
$db->query("SET NAMES `UTF8`");
// Подключение дополнительных функций;
include $_SERVER['DOCUMENT_ROOT'] . '/functions.php';
示例15: MySQL
<?php
ob_start('ob_gzhandler');
include_once '../import/constants.php';
include '../import/config_database.php';
include '../import/class.mysql.php';
include '../import/functions.php';
checkSession();
// Open MySQL Connection
$SQL = new MySQL();
$SQL->connect();
if (!isset($_REQUEST['ACTION'])) {
$_REQUEST['ACTION'] = '';
} else {
$_REQUEST['ACTION'] = htmlspecialchars((string) $_REQUEST['ACTION'], ENT_QUOTES);
}
if (!isset($_REQUEST['ID'])) {
$_REQUEST['ID'] = '';
} else {
$_REQUEST['ID'] = (int) $_REQUEST['ID'];
}
if (!isset($_REQUEST['TRANSFER'])) {
$_REQUEST['TRANSFER'] = '';
} else {
$_REQUEST['TRANSFER'] = htmlspecialchars((string) $_REQUEST['TRANSFER'], ENT_QUOTES);
}
$action = $_REQUEST['ACTION'];
$login_id = $_REQUEST['ID'];
$transfer_id = $_REQUEST['TRANSFER'];
$id_service = isset($_REQUEST['IDSERVICE']) ? (int) $_REQUEST['IDSERVICE'] : "";
$operator_login_id = $_REQUEST['OPERATORID'] = (int) $_REQUEST['OPERATORID'];