本文整理汇总了PHP中MySQL类的典型用法代码示例。如果您正苦于以下问题:PHP MySQL类的具体用法?PHP MySQL怎么用?PHP MySQL使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MySQL类的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: get_uri_data
return FALSE;
}
}
function get_uri_data($args)
{
$hmdb = new MySQL(true, DB_NAME, DB_HOST, DB_USER, DB_PASSWORD, DB_CHARSET);
if (!is_array($args)) {
parse_str($args, $args);
}
if (isset($args['uri'])) {
$uri = $args['uri'];
} else {
$uri = FALSE;
}
if (isset($args['id'])) {
$id_uri = $args['id'];
} else {
$id_uri = FALSE;
}
$tableName = DB_PREFIX . "request_uri";
if (is_numeric($id_uri)) {
$whereArray = array('id' => MySQL::SQLValue($id_uri));
} else {
$whereArray = array('uri' => MySQL::SQLValue($uri));
}
$hmdb->SelectRows($tableName, $whereArray);
if ($hmdb->HasRecords()) {
$row = $hmdb->Row();
return $row;
} else {
示例3: inicializar
function inicializar()
{
$db = new MySQL();
$sql = "create table " . $this->tabla . "(" . "usuario integer(10) not null," . "alias varchar(128) not null," . "clave varchar(128) not null," . "fecha date not null," . "hora time not null," . "estado varchar(32) not null," . "primary key (usuario)" . ");";
$consulta = $db->sql_query($sql);
$db->sql_close();
}
示例4: login
function login($email, $password)
{
require_once 'mysql/mysql.php';
require 'mysql/mysql_settings.php';
$mysql = new MySQL($mysql_user, $mysql_pw, $mysql_server, $mysql_db);
$request = 'SELECT idUser, name, valid, picture FROM User WHERE user.email="' . $email . '" AND user.password="' . $password . '";';
$response = $mysql->request($request);
$response = json_decode(json_encode($response), true);
/**
* pr�fen der request
* @return 'request failed' -> fehlgeschlagene mysql anfrage
* 'wrong user' -> kein eintrag gefunden
* 'wrong password' -> keine Passwort�bereinstimmung
* 'invalid' -> noch nicht freigeschalteter account
*/
if (!$response) {
$echo = mysqli_error($mysql->getCon());
} else {
if (empty($response)) {
$echo = 'wrong user';
} else {
if ($request[0]['valide'] == 0) {
$echo = 'invalid';
} else {
$_SESSION['idUser'] = $response['idUser'];
$_SESSION['name'] = $response['name'];
$_SESSION['picture'] = $response['picture'];
$echo = 'done';
}
}
}
return $echo;
}
示例5: checkNeededDataGoogleSearchAnalytics
/**
* Query database. Retrun all values from a table
*
* @param $table String Table name
*
* @returns Object Database records. MySQL object
*/
public function checkNeededDataGoogleSearchAnalytics($website)
{
$core = new Core();
//Load core
$mysql = new MySQL();
//Load MySQL
$now = $core->now();
/* Identify date range */
$dateStartOffset = self::GOOGLE_SEARCH_ANALYTICS_MAX_DATE_OFFSET + self::GOOGLE_SEARCH_ANALYTICS_MAX_DAYS;
$dateStart = date('Y-m-d', strtotime('-' . $dateStartOffset . ' days', $now));
$dateEnd = date('Y-m-d', strtotime('-' . self::GOOGLE_SEARCH_ANALYTICS_MAX_DATE_OFFSET . ' days', $now));
/* Query database for dates with data */
$query = "SELECT COUNT( DISTINCT date ) AS record, date FROM " . MySQL::DB_TABLE_SEARCH_ANALYTICS . " WHERE domain LIKE '" . $website . "' AND date >= '" . $dateStart . "' AND date <= '" . $dateEnd . "' GROUP BY date";
$result = $mysql->query($query);
/* Create array from database response */
$datesWithData = array();
foreach ($result as $row) {
array_push($datesWithData, $row['date']);
}
/* Get date rante */
$dates = $core->getDateRangeArray($dateStart, $dateEnd);
/* Loop through dates, removing those with data */
foreach ($dates as $index => $date) {
if (in_array($date, $datesWithData)) {
unset($dates[$index]);
}
}
/* Reindex dates array */
$dates = array_values($dates);
$returnArray = array('dateStart' => $dateStart, 'dateEnd' => $dateEnd, 'datesWithNoData' => $dates);
return $returnArray;
}
示例6: register
function register($email, $password, $username)
{
require_once 'mysql/mysql.php';
require 'mysql/mysql_settings.php';
/**
* Establish new connection
* Check if email is already registered
* If so give out failure message, otherwise give out success
*/
$mysql = new MySQL($mysql_user, $mysql_pw, $mysql_server, $mysql_db);
/**
*Check if email is registered
*/
$request = 'SELECT user.idUser FROM user WHERE user.email="' . $email . '";';
$response = $mysql->request($request);
$response = json_decode(json_encode($response), true);
//If so return failure message
if (!empty($response)) {
$echo = 'invalid email';
return $echo;
}
/**
* If not put user into database
*/
$request = 'INSERT INTO user(name,password,email,valid) VALUES ("' . $username . '","' . $password . '","' . $email . '",0);';
$response = $mysql->insert($request);
//Check if insertion worked out
if (!$response) {
$echo = mysqli_error($mysql->getCon());
} else {
$echo = 'done';
}
//Return result
return $echo;
}
示例7: inicializar
function inicializar()
{
$db = new MySQL();
$sql = "";
$consulta = $db->sql_query($sql);
$db->sql_close();
}
示例8: 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);
}
示例9: admin_cp_login
/** Đăng nhập admin cp */
function admin_cp_login()
{
global $hmuser;
$hmdb = new MySQL(true, DB_NAME, DB_HOST, DB_USER, DB_PASSWORD, DB_CHARSET);
hook_action('admin_cp_login');
$user_login = hm_post('login');
$password = hm_post('password');
$logmein = hm_post('log-me-in');
if (is_numeric($logmein)) {
$tableName = DB_PREFIX . "users";
$whereArray = array('user_login' => MySQL::SQLValue($user_login));
$hmdb->SelectRows($tableName, $whereArray);
if ($hmdb->HasRecords()) {
$row = $hmdb->Row();
$salt = $row->salt;
$user_pass = $row->user_pass;
$password_encode = hm_encode_str(md5($password . $salt));
if ($password_encode == $user_pass) {
$time = time();
$ip = hm_ip();
$cookie_array = array('time' => $time, 'ip' => $ip, 'user_login' => $user_login, 'admincp' => 'yes');
$cookie_user = hm_encode_str($cookie_array);
setcookie('admin_login', $cookie_user, time() + COOKIE_EXPIRES, '/');
$_SESSION['admin_login'] = $cookie_user;
return json_encode(array('status' => 'success', 'mes' => _('Đăng nhập thành công')));
} else {
return json_encode(array('status' => 'error', 'mes' => _('Sai mật khẩu')));
}
} else {
return json_encode(array('status' => 'error', 'mes' => _('Không có tài khoản này')));
}
}
}
示例10: validationmail
function validationmail($email)
{
require_once 'mysql/mysql.php';
require 'mysql/mysql_settings.php';
//Build mysql connection
$mysql = new MySQL($mysql_user, $mysql_pw, $mysql_server, $mysql_db);
//Create request
$request = 'INSERT INTO validationmails(email) VALUES ("' . $email . '");';
//Perform request
$response = $mysql->insert($request);
//Check if request was successfull
if (!$response) {
$echo = mysqli_error($mysql->getCon());
} else {
$id = $mysql->insert_id;
}
return email($email, '
Hi ' . $user . ',
um loszulegen klick einfach auf den Link und los geht\'s!
http://fragdichab.de/?p=1&id=' . $id . '&req=validation
Sch�ne Gr��e,
Ruben & Jannes
', 'Bestaetigungsmail');
}
示例11: create_multiple_choice_question
function create_multiple_choice_question($modul_name, $theme_name, $created_by, $question, $answer1, $desc1, $answer2, $desc2, $answer3, $desc3, $answer4, $desc4, $correct, $difficulty, $difficulty_num)
{
$mysql = new MySQL($mysql_user, $mysql_pw, $mysql_server, $mysql_db);
//Start transaction
$response = $mysql->request("START TRANSACTION;");
if (!$response) {
$echo = mysqli_error($mysql->getCon());
return $echo;
}
//Create basic question
create_basic_question($course_name, $modul_name, $theme_name, $created_by, $mysql);
//Check if return value is error message, if so propagate
if ($question_id[0] == '#') {
return $question_id;
}
//If id build corresponding multiple choice question
$request = "INSERT INTO `Multiplichoice` " . "(`idQuestions`, `idMultiplichoice`, `question`, `answer1`, `desc1`, `answer2`, `desc2`, `answer3`, `desc3`, `answer4`, `desc4`, `correct`, `difficulty`, `quality`, `difficulty_num`, `qualitiy_num`) " . "VALUES (" . $question_id . ", NULL, " . $question . "," . $answer1 . "," . $desc1 . "," . $answer2 . "," . $desc2 . "," . $answer3 . "," . $desc3 . "," . $answer4 . "," . $desc4 . "," . $correct . "," . $difficulty . " NULL, 1, NULL);";
$response = $mysql->request($request);
//If not successful abort transaction
if (!$response) {
$echo = mysqli_error($mysql->getCon());
$response = $mysql->request("ROLLBACK;");
return $echo;
}
//Else commit and see if commit was successful
$response = $mysql->request("COMMIT;");
if (!$response) {
$echo = mysqli_error($mysql->getCon());
$response = $mysql->request("ROLLBACK;");
return $echo;
}
//If all worked out commit
return "success";
}
示例12: insertDiscuss
public static function insertDiscuss($disObj)
{
$mysql = new MySQL();
$res = $mysql->insert("page_discs", $disObj);
$mysql->closeCon();
PageService::updateDisNum($disObj['pageid']);
return $res;
}
示例13: getPage
public static function getPage($pageid)
{
$sql = "select a.id,a.pageid,a.title,a.viewnum,a.cover,a.imgnum,a.disnum,a.praisenum,a.status,a.cuserid,a.cusername,\n a.cdate,a.udate ,b.img\n from page a left join page_img b\n on a.pageid=b.pageid where a.pageid=" . $pageid;
$mysql = new MySQL();
$res = $mysql->executeReturnObj($sql);
$mysql->closeCon();
return $res;
}
示例14: getIconByName
public static function getIconByName($name)
{
$sql = "select icon from emotion where value='" . $name . "'";
$mysql = new MySQL();
$res = $mysql->executeReturnFirstObj($sql);
$mysql->closeCon();
return $res;
}
示例15: load
public function load(&$mensaje)
{
$sql = $this->_crearLoad();
$bd = new MySQL();
$sql->addEjecutar(':codigo', $this->_codigo);
$ejecucion = $sql->generarEjecucion();
return $bd->ejecutar($sql, $ejecucion, $mensaje);
}