当前位置: 首页>>代码示例>>PHP>>正文


PHP Dal::get_connection方法代码示例

本文整理汇总了PHP中Dal::get_connection方法的典型用法代码示例。如果您正苦于以下问题:PHP Dal::get_connection方法的具体用法?PHP Dal::get_connection怎么用?PHP Dal::get_connection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Dal的用法示例。


在下文中一共展示了Dal::get_connection方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: user_search

 /**
  * Updated search method for users. Search type can also be specified with every field one is searching for
  * e.g $search_item['first_name'] = array('value'=> 'test', 'type'=> LIKE_SEARCH) here type defines the search type
  * in this case it is LIKE SEARCH (constant defined in api_constants.php) means value
  * will be searched field_value = '%test%'
  * For date of birth we can specify date range like $search_item['dob'] = array('value'=>
  * array('lower_limit'=>200400, 'upper_limit'=>300500), 'type'=> RANGE_SEARCH)
  * This method will help us to search for value given in range and will give more freedom than the
  * method load_info_by_search which uses only LIKE to search for values.
  */
 public static function user_search($search_item, $user_id, $network_id = NULL, $cnt = FALSE, $show = 'ALL', $page = 0, $sort_by = 'U.created', $direction = 'DESC', $condition = NULL)
 {
     Logger::log("Enter: User::user_search");
     $db = Dal::get_connection();
     $data = array();
     $uids = array();
     $i = 0;
     $j = 1;
     $PEARObject = new PEAR();
     $order_by = $sort_by . ' ' . $direction;
     if ($show == 'ALL' || $cnt == TRUE) {
         $limit = '';
     } else {
         $start = ($page - 1) * $show;
         $limit = 'LIMIT ' . $start . ',' . $show;
     }
     // ---- fix by Z.Hron: We don't need to read all data to count rows! Use MySQL function COUNT() in future!
     $search_string = "SELECT (U.user_id) as uid, U.first_name as first_name, U.login_name as login_name, U.picture as picture, UP.field_perm as field_perm, count(U.user_id) as counts, U.created";
     if ($cnt) {
         $search_string = "SELECT count(U.user_id) as counts, (U.user_id) as uid";
     }
     // ---- EOF
     if ($network_id) {
         $search_string .= " FROM users AS U LEFT OUTER JOIN user_profile_data AS UP ON UP.user_id = U.user_id INNER JOIN networks_users AS NU ON U.user_id = NU.user_id AND NU.network_id = ?  ";
         $data[] = $network_id;
     } else {
         $search_string .= " FROM users AS U LEFT OUTER JOIN user_profile_data AS UP ON UP.user_id = U.user_id  ";
     }
     if (!empty($search_item['group_id'])) {
         $group_id = $search_item['group_id']['value'];
         unset($search_item['group_id']);
         $search_string .= " INNER JOIN {groups_users} AS GU ON U.user_id = GU.user_id AND GU.group_id = ?  ";
         $data[] = $group_id;
     }
     if (!empty($search_item['in_relation'])) {
         $relation_id = $search_item['in_relation']['value'];
         $search_string .= " INNER JOIN {relations} AS RU\n        ON U.user_id = RU.relation_id\n        AND RU.user_id = ? ";
         $data[] = $relation_id;
         if (!empty($search_item['in_relation']['type'])) {
             $status = $search_item['in_relation']['type'];
             $search_string .= "  AND RU.status = ? ";
             $data[] = $status;
         }
         unset($search_item['in_relation']);
     }
     if (!empty($condition)) {
         $search_string .= " WHERE {$condition} AND ";
     } else {
         $search_string .= " WHERE 1 AND ";
         // field_perm > 0 AND "; // removed - field_perm checked for each field in code bellow!
     }
     $search_items_count = count($search_item);
     if ($search_items_count > 0) {
         $counter = 0;
         foreach ($search_item as $field_name => $field_details) {
             $counter++;
             switch ($field_details['type']) {
                 case AGE_SEARCH:
                     //date of birth will be saved in the formay YYYY-MM-DD
                     $search_string .= '( UP.field_name = ? AND UP.field_value BETWEEN DATE(DATE_ADD(NOW(), INTERVAL ? YEAR)) AND DATE(DATE_ADD(NOW(), INTERVAL ? YEAR)) AND UP.field_perm <> ?)';
                     $data[] = $field_name;
                     $data[] = $field_details['value']['upper_limit'] * -1;
                     $data[] = $field_details['value']['lower_limit'] * -1;
                     $data[] = NONE;
                     break;
                 case GREATER_THAN:
                     $search_string .= '( UP.field_name = ? AND UP.field_value ' . $field_details['type'] . ' ? AND UP.field_perm <> ? )';
                     $data[] = $field_name;
                     $data[] = $field_details['value'];
                     $data[] = NONE;
                     break;
                 case RANGE_SEARCH:
                     $search_string .= '( UP.field_name = ? AND UP.field_value ' . $field_details['type'] . '  ? AND ? AND UP.field_perm <> ? )';
                     $data[] = $field_name;
                     $data[] = $field_details['value']['lower_limit'];
                     $data[] = $field_details['value']['upper_limit'];
                     $data[] = NONE;
                     break;
                 case LIKE_SEARCH:
                     if (!empty($field_details['ignore_perm']) && $field_details['ignore_perm'] == true) {
                         $search_string .= '( UP.field_name = ? AND UP.field_value ' . $field_details['type'] . ' ? )';
                         $data[] = $field_name;
                         $data[] = '%' . $field_details['value'] . '%';
                     } else {
                         $search_string .= '( UP.field_name = ? AND UP.field_value ' . $field_details['type'] . ' ? AND UP.field_perm <> ? )';
                         $data[] = $field_name;
                         $data[] = '%' . $field_details['value'] . '%';
                         $data[] = NONE;
                     }
                     break;
//.........这里部分代码省略.........
开发者ID:CivicCommons,项目名称:people-aggregator,代码行数:101,代码来源:User.php

示例2: dirname

<?php

require_once dirname(__FILE__) . '/../config.inc';
require_once "{$path_prefix}/db/Dal/Dal.php";
require_once "{$path_prefix}/db/Dal/DbUpdate.php";
require_once "{$path_prefix}/api/Network/Network.php";
// Re-include constants.php to make sure we have the most up to date
// constants.  If we are in the middle of an update and this script is
// being included by web/update/run_scripts.php, we might not have all
// the constants.
include "{$path_prefix}/web/includes/constants.php";
// $settings_new contains the mapping of page names to modules they contain.
global $settings_new;
$db = Dal::get_connection();
foreach (DbUpdate::get_valid_networks() as $net_address) {
    set_time_limit(30);
    $net = Network::get_network_by_address($net_address);
    $table_name = 'page_default_settings';
    if ($net->type != MOTHER_NETWORK_TYPE) {
        // 1 for home network
        $table_name = $net->address . '_' . $table_name;
    }
    $sql = ' TRUNCATE TABLE ' . $table_name;
    $res = Dal::query($sql);
    foreach ($settings_new as $page_id => $v1) {
        $page_name = $v1['page_name'];
        $data = $v1['data'];
        $settings_data = serialize($data);
        $is_configurable = isset($v1['is_configurable']) ? $v1['is_configurable'] : FALSE;
        //default value will be false is not specified
        $sql = "INSERT INTO {$table_name} (page_id, page_name, default_settings, is_configurable) VALUES (?, ?, ?, ?)";
开发者ID:CivicCommons,项目名称:oldBellCaPA,代码行数:31,代码来源:script_module_settings_data.php

示例3: quote

 public static function quote($s)
 {
     return Dal::get_connection()->escapeSimple($s);
 }
开发者ID:Cyberspace-Networks,项目名称:PeopleAggregator,代码行数:4,代码来源:Dal.php

示例4: main

  function main()
  {
    $this->db = Dal::get_connection();

    $this->note("Doing database update");

    // We use $this->db->getOne() below instead of Dal::query_one() as
    // the first time this script is run, the mc_db_status table will
    // not exist, which will fire an exception with Dal::query_one()
    // and break the installation.  Please don't change this to
    // Dal::query_one()!  -PP 2006-11-15
    $db_status = $this->db->getOne("SELECT * FROM mc_db_status LIMIT 1");
    
    if (!DB::isError($db_status))
    {
      $this->note("mc_db_status table in place");
    }
    else
    {
      $this->note("Creating mc_db_status table");
      $this->query("CREATE TABLE mc_db_status (stmt_key VARCHAR(255) NOT NULL, PRIMARY KEY(stmt_key))");
    }

    // add network column
    if (!$this->column_exists("mc_db_status", "network")) {
      $this->query("ALTER TABLE mc_db_status ADD COLUMN network VARCHAR(50) NOT NULL DEFAULT ''");
      $this->query("ALTER TABLE mc_db_status DROP PRIMARY KEY");
      $this->query("ALTER TABLE mc_db_status ADD PRIMARY KEY(stmt_key, network)");
    }

    /* 'broken' col disabled for now - use $this->broken_networks instead.
    // make sure the network table has the 'broken' column before we get started
        if (!$this->column_exists("networks", "broken")) {
      Dal::query("ALTER TABLE networks ADD COLUMN broken BOOLEAN DEFAULT '0'");
    }*/

    // find networks which have their tables (i.e. skip over broken networks)
    $this->networks = DbUpdate::get_valid_networks();

    $override = @$_GET['override'];
    if (!empty($override))
    {
      try {
	Dal::query("INSERT INTO mc_db_status SET stmt_key=?", Array($override));
      } catch (PAException $e) {
	echo "<p>exception trying to override: ".$e->getMessage()."</p>";
      }
    }

    $this->do_updates();

    if (!$this->quiet) {
      //        $this->dump_schema();
      $this->note("db update done.");
    }
  }
开发者ID:CivicCommons,项目名称:oldBellCaPA,代码行数:56,代码来源:db_update.php

示例5: main

 function main()
 {
     $this->db = Dal::get_connection();
     $this->write('<table>');
     $this->note('Doing database update');
     // We use $this->db->getOne() below instead of Dal::query_one() as
     // the first time this script is run, the mc_db_status table will
     // not exist, which will fire an exception with Dal::query_one()
     // and break the installation.  Please don't change this to
     // Dal::query_one()!  -PP 2006-11-15
     $db_status = $this->db->getOne('SELECT * FROM mc_db_status LIMIT 1');
     if (!DB::isError($db_status)) {
         $this->note('mc_db_status table in place');
     } else {
         $this->note('Creating mc_db_status table');
         $this->query('CREATE TABLE mc_db_status (stmt_key VARCHAR(255) NOT NULL, PRIMARY KEY(stmt_key))');
     }
     // add network column
     if (!$this->column_exists('mc_db_status', 'network')) {
         $this->query('ALTER TABLE mc_db_status ADD COLUMN network VARCHAR(50) NOT NULL DEFAULT \'\'');
         $this->query('ALTER TABLE mc_db_status DROP PRIMARY KEY');
         $this->query('ALTER TABLE mc_db_status ADD PRIMARY KEY(stmt_key, network)');
     }
     // find networks which have their tables (i.e. skip over broken networks)
     $this->networks = DbUpdate::get_valid_networks();
     $override = @$_GET['override'];
     if (!empty($override)) {
         try {
             Dal::query('INSERT INTO mc_db_status SET stmt_key=?', array($override));
         } catch (PAException $e) {
             echo '<p>exception trying to override: ', $e->getMessage(), '</p>';
         }
     }
     $this->do_updates();
     if (!$this->quiet) {
         $this->note('CORE db updates done.');
         $this->write('</table>');
     }
 }
开发者ID:CivicCommons,项目名称:people-aggregator,代码行数:39,代码来源:db_update_page.class.php

示例6: user_search

 /**
  * Updated search method for users. Search type can also be specified with every field one is searching for
  * e.g $search_item['first_name'] = array('value'=> 'test', 'type'=> LIKE_SEARCH) here type defines the search type 
  * in this case it is LIKE SEARCH (constant defined in api_constants.php) means value 
  * will be searched field_value = '%test%'
  * For date of birth we can specify date range like $search_item['dob'] = array('value'=> 
  * array('lower_limit'=>200400, 'upper_limit'=>300500), 'type'=> RANGE_SEARCH)
  * This method will help us to search for value given in range and will give more freedom than the 
  * method load_info_by_search which uses only LIKE to search for values.
  */
 public static function user_search($search_item, $user_id, $network_id = NULL, $cnt = FALSE, $show = 'ALL', $page = 0, $sort_by = 'U.created', $direction = 'DESC')
 {
     Logger::log("Enter: User::user_search");
     $db = Dal::get_connection();
     $data = array();
     $uids = array();
     $i = 0;
     $j = 1;
     $order_by = $sort_by . ' ' . $direction;
     if ($show == 'ALL' || $cnt == TRUE) {
         $limit = '';
     } else {
         $start = ($page - 1) * $show;
         $limit = 'LIMIT ' . $start . ',' . $show;
     }
     if ($network_id) {
         $search_string = "SELECT (U.user_id) as uid, U.first_name as first_name, U.login_name as login_name, U.picture as picture, UP.field_perm as field_perm, count(U.user_id) as counts FROM users AS U LEFT OUTER JOIN user_profile_data AS UP ON UP.user_id = U.user_id INNER JOIN networks_users AS NU ON U.user_id = NU.user_id AND NU.network_id = ? WHERE ";
         $data[] = $network_id;
     } else {
         $search_string = "SELECT (U.user_id) as uid, U.first_name as first_name, U.login_name as login_name, U.picture as picture, UP.field_perm as field_perm, count(U.user_id) as counts FROM users AS U LEFT OUTER JOIN user_profile_data AS UP ON UP.user_id = U.user_id WHERE ";
     }
     $search_items_count = count($search_item);
     if ($search_items_count > 0) {
         $counter = 0;
         foreach ($search_item as $field_name => $field_details) {
             $counter++;
             switch ($field_details['type']) {
                 case AGE_SEARCH:
                     //date of birth will be saved in the formay YYYY-MM-DD
                     $search_string .= '( UP.field_name = ? AND UP.field_value BETWEEN DATE(DATE_ADD(NOW(), INTERVAL ? YEAR)) AND DATE(DATE_ADD(NOW(), INTERVAL ? YEAR)) AND UP.field_perm <> ?)';
                     $data[] = $field_name;
                     $data[] = $field_details['value']['upper_limit'] * -1;
                     $data[] = $field_details['value']['lower_limit'] * -1;
                     $data[] = NONE;
                     break;
                 case GREATER_THAN:
                     $search_string .= '( UP.field_name = ? AND UP.field_value ' . $field_details['type'] . ' ? AND UP.field_perm <> ? )';
                     $data[] = $field_name;
                     $data[] = $field_details['value'];
                     $data[] = NONE;
                     break;
                 case RANGE_SEARCH:
                     $search_string .= '( UP.field_name = ? AND UP.field_value ' . $field_details['type'] . '  ? AND ? AND UP.field_perm <> ? )';
                     $data[] = $field_name;
                     $data[] = $field_details['value']['lower_limit'];
                     $data[] = $field_details['value']['upper_limit'];
                     $data[] = NONE;
                     break;
                 case LIKE_SEARCH:
                     $search_string .= '( UP.field_name = ? AND UP.field_value ' . $field_details['type'] . ' ? AND UP.field_perm <> ? )';
                     $data[] = $field_name;
                     $data[] = '%' . $field_details['value'] . '%';
                     $data[] = NONE;
                     break;
                 default:
                     $search_string .= '( UP.field_name = ? AND UP.field_value ' . $field_details['type'] . ' ? AND UP.field_perm <> ? )';
                     $data[] = $field_name;
                     $data[] = $field_details['value'];
                     $data[] = NONE;
             }
             $search_string .= $search_items_count == $counter ? ' AND ' : ' OR ';
         }
     }
     $search_string .= " U.is_active = ? GROUP BY uid HAVING counts = ? ORDER BY {$order_by} {$limit}";
     $data[] = ACTIVE;
     $data[] = $search_items_count;
     // Logger::log(print_r($search_item,1)."\n$search_string\n".print_r($data,1), LOGGER_ACTION);
     $res = Dal::query($search_string, $data);
     if (PEAR::isError($res)) {
         Logger::log(" Throwing exception DB_QUERY_FAILED | Message: {$res->getMessage}()", LOGGER_ERROR);
         throw new PAException(DB_QUERY_FAILED, $res->getMessage());
     }
     if ($cnt) {
         return $res->numRows();
     }
     $uid_array = array();
     if ($res->numrows() > 0) {
         $i = 0;
         while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT)) {
             $uid_array[$i]['user_id'] = $row->uid;
             $uid_array[$i]['login_name'] = $row->login_name;
             $uid_array[$i]['picture'] = $row->picture;
             $uid_array[$i]['first_name'] = $row->first_name;
             $uid_array[$i]['field_perm'] = $row->field_perm;
             $i++;
         }
     }
     // search according to perm
     $sql = "Select user_id from {relations} where relation_id = {$user_id}";
     $res = Dal::query($sql);
//.........这里部分代码省略.........
开发者ID:CivicCommons,项目名称:oldBellCaPA,代码行数:101,代码来源:User.php


注:本文中的Dal::get_connection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。