本文整理汇总了PHP中SafeMySQL类的典型用法代码示例。如果您正苦于以下问题:PHP SafeMySQL类的具体用法?PHP SafeMySQL怎么用?PHP SafeMySQL使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SafeMySQL类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getCountryDefault
public static function getCountryDefault($countryID)
{
if (!$countryID) {
return false;
}
$sql = "SELECT *\n FROM `taxes`\n WHERE `country_id` = ?s\n AND `state_code` IS NULL";
$db = self::$_msql = SafeMySQL::getInstance();
$result = $db->getRow($sql, $countryID);
if ($result) {
$tax = new Tax();
$tax->fillFromArray($result);
return $tax;
}
return false;
}
示例2: show
function show()
{
$configuration = new Config();
$database = new SafeMySQL(array('user' => $configuration->db->username, 'pass' => $configuration->db->password, 'db' => $configuration->db->database, 'charset' => $configuration->db->charset));
$data = $database->getAll('SELECT * FROM students');
$response = new Response();
$response->setContent(json_encode($data));
$response->send();
}
示例3: __construct
public function __construct()
{
if (!self::$db) {
self::$db = SafeMySQL::getInstance();
}
parent::__construct();
}
示例4: beforeSave
public function beforeSave()
{
// make sure there isn't already a record with the same country and state code
$db = self::$_msql = SafeMySQL::getInstance();
$sql = "SELECT tax_id\n FROM `taxes`\n WHERE `country_id` = ?s";
if ($this->state_code) {
$sql .= " and state_code = ?s";
} else {
$sql .= " and state_code is NULL";
}
if ($this->tax_id) {
$sql .= " and tax_id = ?i";
if ($this->state_code) {
$result = $db->getOne($sql, $this->country_id, $this->state_code, $this->tax_id);
} else {
$result = $db->getOne($sql, $this->country_id, $this->tax_id);
}
} else {
if ($this->state_code) {
$result = $db->getOne($sql, $this->country_id, $this->state_code);
} else {
$result = $db->getOne($sql, $this->country_id);
}
}
if ($result) {
return false;
} else {
return TRUE;
}
}
示例5: firePixelPb
public static function firePixelPb($model)
{
$db = SafeMySQL::getInstance();
if (!$model instanceof Order) {
$model = Order::model()->findByPk($model);
}
if (!$model->order_id) {
return false;
}
// NOTE: temp. If a payment bank in array - we don't need to fire pixel
if ($model->payment && is_object($model->payment) && $model->payment->num2 && in_array($model->payment->num2, self::$_bannedBins) && in_array($model->campaign_id, self::$_bannedCampaigns)) {
return false;
}
$fire = false;
if ($model->aff_id) {
$sql = 'SELECT * FROM `pixel_rates` WHERE `campaign_id` = ?i AND `method_id` = ?i AND `aff_id` = ?i';
$result = $db->query($sql, $model->campaign_id, $model->payment->method_id, $model->aff_id);
$count_rows = $result->num_rows;
} else {
$count_rows = 0;
}
if (!$model->aff_id || !$count_rows) {
$sql = 'SELECT * FROM `pixel_rates` WHERE `campaign_id` = ?i AND `method_id` = ?i AND `aff_id` IS NULL';
$result = $db->query($sql, $model->campaign_id, $model->payment->method_id);
if (!$result->num_rows) {
$fire = true;
} else {
$fire_result = $db->fetch($result);
if ($fire_result['rate']) {
$fire = true;
}
if ($model->aff_id) {
$r = $fire_result['rate'] == 0 ? 0 : 1;
$sql = 'INSERT IGNORE INTO `pixel_rates` (`campaign_id`, `method_id`, `aff_id`, `rate`, `total_fired`, `total_orders`)
SELECT `campaign_id`, `method_id`, ?i, `rate`, ' . $r . ', 1
FROM `pixel_rates` WHERE `campaign_id` = ?i AND `method_id` = ?i AND `aff_id` IS NULL';
$db->query($sql, $model->aff_id, $model->campaign_id, $model->payment->method_id);
}
}
} else {
$fire_result = $db->fetch($result);
if ($fire_result['rate'] != 0 && ($fire_result['total_orders'] == 0 || 100 * $fire_result['total_fired'] / ($fire_result['total_orders'] + 1) < $fire_result['rate'])) {
$sql = 'UPDATE `pixel_rates` SET `total_fired` = `total_fired` + 1, `total_orders` = `total_orders` + 1 WHERE `campaign_id` = ?i AND `method_id` = ?s AND `aff_id` = ?i';
$db->query($sql, $model->campaign_id, $model->payment->method_id, $model->aff_id);
$fire = true;
} else {
$sql = 'UPDATE `pixel_rates` SET `total_orders` = `total_orders` + 1 WHERE `campaign_id` = ?i AND `method_id` = ?s AND `aff_id` = ?i';
$db->query($sql, $model->campaign_id, $model->payment->method_id, $model->aff_id);
}
}
if ($fire) {
$sql = 'UPDATE `orders` SET `pixel_fired` = 1 WHERE `order_id` = ?i';
$db->query($sql, $model->order_id);
exec('/usr/bin/php-cli /home/pinnacle/public_html/lj3/nws/pixels_pb.php ' . $model->order_id . ' > /dev/null 2>&1 &');
}
}
示例6: getAttachedByCampaign
public static function getAttachedByCampaign($campaign_id, $auto = true)
{
$db = SafeMySQL::getInstance();
$sql = "SELECT ca.`campattach_id`,\n\t\t\t\t\t\tca.`campaign_id`,\n ca.`campaign_attach_id`\n\t\t FROM `campaigns_attach` as ca\n WHERE ca.`campaign_id` = ?i";
if ($auto) {
$sql .= " and ca.`auto_attach` = 1";
}
$sql .= " ORDER BY ca.`campattach_id` ASC";
return $db->getAll($sql, $campaign_id);
}
示例7: fillFromDatabase
private static function fillFromDatabase()
{
$cacheID = "all_currencies";
self::$_allCurrencies = AF::cache()->get($cacheID);
if (!self::$_allCurrencies) {
$db = self::$_msql = SafeMySQL::getInstance();
$sql = "SELECT * FROM `currency`";
self::$_allCurrencies = $db->getInd('currency_id', $sql);
AF::cache()->set($cacheID, self::$_allCurrencies);
}
}
示例8: getResultsByCustomerId
public function getResultsByCustomerId($id, $cc = true)
{
if (!$id) {
return array();
}
$db = self::$_msql = SafeMySQL::getInstance();
$sql = "SELECT\n\t\t\tp.`payment_id`,\n\t\t\tp.`customer_id`,\n\t\t\tp.`method_id`,\n\t\t\tp.`num1`,\n\t\t\tp.`num2`,\n\t\t\tp.`num3`,\n\t\t\tp.`num4`,\n\t\t\tp.`txt1`,\n\t\t\tp.`txt2`,\n\t\t\tp.`txt3`,\n\t\t\tp.`txt4`";
$sql .= $cc ? " , p.`note1`" : '';
$sql .= "FROM `payments` as p\n\t\t\tWHERE p.`customer_id`=?i";
$sqlParse = $db->parse($sql, $id);
return $this->getSqlParse($sqlParse);
}
示例9: getDoubleShippingSKUArray
public static function getDoubleShippingSKUArray($campaignArray, $campaignID)
{
self::$DoubleShippingSKUArray = array();
if (!$campaignArray) {
return array();
}
$db = SafeMySQL::getInstance();
$sql = "SELECT cp.`campaign_id`\n FROM `products` as p\n JOIN `campaigns_products` as cp ON p.`product_id` = cp.`product_id`\n WHERE cp.`campaign_id` IN (?a)\n AND p.`product_shipping_sku` != ''";
$result = $db->getAll($sql, $campaignArray);
$resultArray = array();
foreach ($result as $item) {
$resultArray[] = $item['campaign_id'];
}
self::$DoubleShippingSKUArray = in_array($campaignID, $resultArray) ? $resultArray : array();
}
示例10: getResultsById
public function getResultsById($id, $ps = null)
{
if (!$id) {
return array();
}
$db = self::$_msql = SafeMySQL::getInstance();
$sql = "SELECT\n\t\t\t\tpm.`profile_id`,\n\t\t\t\tpm.`method_id`,\n\t\t\t\tm.`method_name`,\n\t\t\t\tm.`method_ref`,\n\t\t\t\tpm.`load_balance`,\n\t\t\t\tg.`system_code`\n FROM `profiles_methods` as pm\n\t\t\t JOIN `methods` as m on m.`method_id` = pm.`method_id`\n\t\t\t JOIN `profiles_gateways` as pg on pg.`profile_id` = pm.`profile_id` and pg.`method_id` = pm.`method_id`\n\t\t\t JOIN `gateways` as g on g.`gateway_id` = pg.`gateway_id`\n WHERE pm.`profile_id` = ?i";
if ($ps && strlen($ps)) {
$sql .= " AND g.`system_code` = ?s";
$sqlParse = $db->parse($sql, $id, $ps);
} else {
$sqlParse = $db->parse($sql, $id);
}
return $this->getSqlParse($sqlParse);
}
示例11: privilegeAction
function privilegeAction()
{
$model = new User();
$model->allFIelds = true;
$id = AF::get($this->params, 'id', 0);
if (!$id) {
throw new AFHttpException(0, 'no_id');
}
if (!$model->setByID($id)) {
throw new AFHttpException(0, 'incorrect_id');
}
$access = new Access();
$access->fillFromUser($model);
$userAccess = $access->getUserUpdateAccess();
ksort($userAccess);
if (isset($_POST['ajax'])) {
$newAcces = AF::get($_POST, 'array');
if ($newAcces) {
$access->setUserAccess($newAcces);
// hack to get the uesrs_access table to update instead of insert
$msql = SafeMySQL::getInstance();
$sql = "SELECT * FROM ?n WHERE user_id = ?i";
$result = $msql->getRow($sql, $access->tableName(), $access->user_id);
if (!empty($result)) {
$access->setIsNewRecord(0);
}
if ($access->save()) {
$model->user_id_updated = $this->user->user_id;
$model->updated = 'NOW():sql';
$model->IsNewRecord = false;
$model->save();
Message::echoJsonSuccess(__('user_access_updated'));
} else {
Message::echoJsonError(__('user_access_not_updated'));
}
} else {
Message::echoJsonError(__('user_access_not_updated'));
}
}
Assets::js('jquery.form');
$this->addToPageTitle('User privilege');
$this->render('privilege', array('userAccess' => $userAccess, 'model' => $model));
}
示例12: updateSites
public static function updateSites($campaignID)
{
$modelCampaign = Campaign::model()->with('domain')->cache()->findByPk($campaignID);
if (!$modelCampaign) {
return false;
}
$db = SafeMySQL::getInstance();
$sql = "SELECT c.`url`,\n c.`campaign_id`,\n c.`country_id`,\n c.`currency_id`\n FROM `campaigns` as c\n WHERE c.`domain_id` = ?i";
$campaigns = $db->getAll($sql, $modelCampaign->domain_id);
$rArray = array();
$cIDs = array();
foreach ($campaigns as $campaign) {
$cIDs[] = $campaign['campaign_id'];
$rArray[$campaign['campaign_id']] = array('main' => array('path' => $campaign['url'], 'campaign_id' => $campaign['campaign_id'], 'country_id' => $campaign['country_id'], 'currency_id' => $campaign['currency_id']), 'products' => array(), 'custom_fields' => array());
$sql = "SELECT `name`, `value`\n FROM `site_variables`\n WHERE (`domain_id`=?i AND`campaign_id`=?i)\n OR (`domain_id`=?i AND `campaign_id` IS NULL)\n OR (`domain_id` IS NULL AND `campaign_id` IS NULL)";
$customFields = $db->getAll($sql, $modelCampaign->domain_id, $campaign['campaign_id'], $modelCampaign->domain_id);
if ($customFields) {
foreach ($customFields as $field) {
$rArray[$campaign['campaign_id']]['custom_fields'][$field['name']] = $field['value'];
}
}
}
$sql = "SELECT p.`product_id`,\n p.`prodcat_id`,\n p.`product_name`,\n p.`product_price`,\n p.`product_weight`,\n p.`product_next_id`,\n p.`subscription_days`,\n cp.`campaign_id`\n FROM `products` as p\n JOIN `campaigns_products` as cp USING (`product_id`)\n WHERE cp.`campaign_id` IN (?a)\n AND cp.`enabled` = 1\n AND cp.`upsell_id` IS NULL";
$products = $db->getAll($sql, $cIDs);
if ($products) {
foreach ($products as $product) {
$campaignID = $product['campaign_id'];
unset($product['campaign_id']);
array_push($rArray[$campaignID]['products'], $product);
}
}
$siteApi = new SiteApi();
if (!$siteApi->createFile(json_encode($rArray))) {
//save an error to the log file
//..
return false;
}
$siteApi->domain = $modelCampaign->domain->url;
$siteApi->update();
}
示例13: array
<?php
require '../php/main/db_connect.php';
require 'mm/parser.php';
$arr = array();
if ($last_id && $page && $user_id) {
$string_object = new SafeMySQL();
$writer = new Writer();
$y = $string_object->getRow("SELECT d_id, other_id, pioneer_id,meter FROM users_dialogs WHERE d_id=?i AND pioneer_id=?i OR d_id=?i AND other_id=?i LIMIT 1", $category, $user_id, $category, $user_id);
if ($y['d_id']) {
$dg = $string_object->getAll("SELECT m.text, m.date, m.mes_id, i.avatar, i.category, i.nickname FROM users_messages m, users_information i WHERE m.d_id=?i AND m.mes_id < ?i AND i.user_id = m.user_id ORDER BY m.mes_id DESC LIMIT 10", $y['d_id'], $last_id);
$avatar = $string_object->getOne('SELECT avatar FROM users_information WHERE user_id=?i', $user_id);
$avatar = file_exists('../upload_image/avatars/pre_150px/' . $avatar . '.jpg') ? $avatar : 'default';
$i = 0;
foreach ($dg as $array) {
$res = array('n0' => $y['d_id'], 'n1' => $array['mes_id'], 'n2' => $array['avatar'], 'n3' => $array['nickname'], 'n4' => $array['date'], 'n5' => $writer->main($array['text'], 1));
$i++;
array_push($arr, $res);
}
unset($array);
}
}
print json_encode($arr);
示例14: long2ip
echo long2ip(2130706433);
die;
//time
$mtime = explode(" ", microtime());
$Smtime = $mtime[1] + $mtime[0];
$start_memory_usage = memory_get_usage();
//timeend---
/**
* User: Anton Antonov
* Date: 6/6/14
* Time: 7:47 AM
*/
@(include_once 'settings/autoload.php');
$productArray['subscription_days'] = 2;
$db = SafeMySQL::getInstance();
$result = array();
$result['status'] = 'upsell';
//$result['discount_next'] = 0;
//$result['created'] = date("Y-m-d H:i:s");
$result['amount_product'] = 11.2;
$result['amount_shipping'] = 0;
$result['amount_refunded'] = 0;
$result['payment_total'] = 0;
//$productArray['product_price'];
$result['pixel_fired'] = 0;
//$result['product_id'] = 111;
$result['shipping_id'] = 111;
//$result['rma_code'] = 'NULL:sql';
$result['recurring'] = $productArray['subscription_days'] ? 0 : 'NULL:sql';
$result['billing_cycle'] = 0;
示例15: demo
<body>
<h2>DbTree 4.2 class demo by Kuzma Feskov</h2>
[<a href="dbtree.php">Manage demo</a>] [<a href="dbtree.php?mode=map">Visual demo (Map)</a>] [<a href="dbtree.php?mode=ajar">Visual demo (Ajar)</a>] [<a href="dbtree.php?mode=branch">Visual demo (Branch)</a>]
<?php
require_once 'classes/safemysql.class.php';
require_once 'classes/DbTree.class.php';
require_once 'classes/DbTreeExt.class.php';
// Data base connect
$dsn['user'] = 'root';
$dsn['pass'] = '';
$dsn['host'] = 'localhost';
$dsn['db'] = 'test';
$dsn['charset'] = 'utf8';
$dsn['errmode'] = 'exception';
define('DEBUG_MODE', false);
$db = new SafeMySQL($dsn);
$sql = 'SET NAMES utf8';
$db->query($sql);
$tree_params = array('table' => 'test_sections', 'id' => 'section_id', 'left' => 'section_left', 'right' => 'section_right', 'level' => 'section_level');
$dbtree = new DbTreeExt($tree_params, $db);
/* ------------------------ NAVIGATOR ------------------------ */
$navigator = 'You are here: ';
if (!empty($_GET['section_id'])) {
$parents = $dbtree->Parents((int) $_GET['section_id'], array('section_id', 'section_name'));
foreach ($parents as $item) {
if (@$_GET['section_id'] != $item['section_id']) {
$navigator .= '<a href="dbtree.php?mode=' . $_GET['mode'] . '§ion_id=' . $item['section_id'] . '">' . $item['section_name'] . '</a> > ';
} else {
$navigator .= '<strong>' . $item['section_name'] . '</strong>';
}
}