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


PHP Db::newDb方法代码示例

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


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

示例1: read_config

 /**
  * read_config reads the config from database and stores it in an array
  * 
  * @return void
  */
 private function read_config()
 {
     // prepare config
     $config = array();
     // get db-object
     $db = Db::newDb();
     // prepare sql-statement
     $sql = "SELECT c.name,c.value\n\t\t\t\tFROM config AS c";
     // execute statement
     $result = $db->query($sql);
     // fetch result
     while (list($name, $value) = $result->fetch_array(MYSQL_NUM)) {
         $config[$name] = $value;
     }
     // set config
     $this->set_config($config);
 }
开发者ID:BackupTheBerlios,项目名称:judointranet,代码行数:22,代码来源:class.Config.php

示例2: dbhierselect_value

 /**
  * dbselect_value the text value for this field from
  * db using the field-config (select_list#select_value)
  * 
  * @return string value from db
  */
 public function dbhierselect_value()
 {
     // get db-object
     $db = Db::newDb();
     // get config
     $config = $this->get_config();
     $sql = explode('|', $config['sql'][2], 3);
     // separate value
     list($v_first, $v_second) = explode('|', $this->get_value(), 2);
     // execute query
     $value = $sql[0] . $v_first . $sql[1] . $v_second . $sql[2];
     $result = $db->query($value);
     // fetch result
     $field_values = $result->fetch_array(MYSQL_ASSOC);
     // return
     return $field_values;
 }
开发者ID:BackupTheBerlios,项目名称:judointranet,代码行数:23,代码来源:class.Field.php

示例3: check_rights

    /**
     * check_rights if the loggedin user has rights on the given table and
     * table_id
     * 
     * @param int $table_id id of the entry
     * @param string $table name of the table
     * @param bool $public if true, include public-access in check
     * @return bool true if user has rights, false otherwise
     */
    public static function check_rights($table_id, $table, $public = false)
    {
        // get groups
        $groups = $_SESSION['user']->groups();
        // get rights for given id and table
        // get db-object
        $db = Db::newDb();
        // prepare sql-statement
        $sql = 'SELECT r.id,r.g_id
				FROM rights AS r
				WHERE r.table_name = "' . $table . '"
				AND r.table_id = ' . (int) $table_id;
        // execute
        $result = $db->query($sql);
        // fetch result
        $all_rights = array();
        while (list($id, $g_id) = $result->fetch_array(MYSQL_NUM)) {
            // set variables to array
            $all_rights[$id] = $g_id;
        }
        // walk through groups and check if in rights
        foreach ($groups as $no => $group_id) {
            if ($public) {
                if (in_array($group_id, $all_rights)) {
                    return true;
                }
            } else {
                if (in_array($group_id, $all_rights) && $group_id != 0) {
                    return true;
                }
            }
        }
        // else return false
        return false;
    }
开发者ID:BackupTheBerlios,项目名称:judointranet,代码行数:44,代码来源:class.Rights.php

示例4: return_all_users

 /**
  * return_all_users returns all users from db as array containing
  * user-objects
  * 
  * @param array $exclude array containing usernames not to include in list
  * @return array array containing all user-objects
  */
 public function return_all_users($exclude = array())
 {
     // prepare return
     $users = array();
     // get db-object
     $db = Db::newDb();
     // prepare sql-statement
     $sql = "SELECT u.username\n\t\t\t\tFROM user AS u";
     // execute statement
     $result = $db->query($sql);
     //fetch result
     while (list($username) = $result->fetch_array(MYSQL_NUM)) {
         // safe object in array
         $user = new User();
         $user->change_user($username, false);
         // exclude
         if (!in_array($username, $exclude)) {
             $users[] = $user;
         }
     }
     // return
     return $users;
 }
开发者ID:BackupTheBerlios,项目名称:judointranet,代码行数:30,代码来源:class.User.php

示例5: check_ann_value

 /**
  * check_ann_value checks if the given calendar-entry has values on the
  * given preset-id
  * 
  * @param int $cid id of the calendar-entry
  * @return bool true if calendar-entry and preset has values, false otherwise
  */
 public static function check_ann_value($cid)
 {
     // get db-object
     $db = Db::newDb();
     // prepare sql-statement
     $sql = "\n\t\t\tSELECT v.id\n\t\t\tFROM value AS v\n\t\t\tWHERE v.table_name = 'calendar'\n\t\t\tAND v.table_id = {$cid}";
     // execute
     $result = $db->query($sql);
     // check result
     if ($result->num_rows > 0) {
         return true;
     } else {
         return false;
     }
 }
开发者ID:BackupTheBerlios,项目名称:judointranet,代码行数:22,代码来源:class.Calendar.php

示例6: writeDb

 /**
  * writeDb writes the protocol-entry to db
  * 
  * @return void
  */
 public function writeDb($action = 'new')
 {
     // prepare timestamp
     $timestamp = date('Y-m-d', strtotime($this->get_date()));
     // get db-object
     $db = Db::newDb();
     // check action
     if ($action == 'new') {
         // insert
         // prepare sql-statement
         $sql = "INSERT INTO protocol\n\t\t\t\t\t\t(id,\n\t\t\t\t\t\tdate,\n\t\t\t\t\t\ttype,\n\t\t\t\t\t\tlocation,\n\t\t\t\t\t\tprotocol,\n\t\t\t\t\t\tpreset_id,\n\t\t\t\t\t\tvalid,\n\t\t\t\t\t\tmember,\n\t\t\t\t\t\towner,\n\t\t\t\t\t\tcorrectable,\n\t\t\t\t\t\trecorder)\n\t\t\t\t\tVALUES (null,'" . $db->real_escape_string($timestamp) . "'," . $db->real_escape_string($this->get_type('i')) . ",'" . $db->real_escape_string($this->get_location()) . "','" . $db->real_escape_string($this->get_protocol()) . "'," . $db->real_escape_string($this->get_preset()->get_id()) . "," . $db->real_escape_string($this->get_valid()) . ",'" . $db->real_escape_string($this->get_member(true, "|")) . "'," . $db->real_escape_string($this->get_owner()) . ",'" . $db->real_escape_string($this->get_correctable()) . "','" . $db->real_escape_string($this->get_recorder()) . "')";
         // execute;
         $db->query($sql);
         // get insert_id
         $insert_id = $db->insert_id;
         // set id and preset_id
         $this->set_id($insert_id);
         // write rights
         try {
             $this->get_rights()->write_db($insert_id);
         } catch (Exception $e) {
             throw new Exception('DbActionUnknown', $e->getCode());
         }
     } elseif ($action == 'update') {
         // update
         // prepare sql-statement
         $sql = "UPDATE protocol\n\t\t\t\t\tSET\n\t\t\t\t\t\tdate='" . $db->real_escape_string($timestamp) . "',\n\t\t\t\t\t\ttype=" . $db->real_escape_string($this->get_type('i')) . ",\n\t\t\t\t\t\tlocation='" . $db->real_escape_string($this->get_location()) . "',\n\t\t\t\t\t\tprotocol='" . $db->real_escape_string($this->get_protocol()) . "',\n\t\t\t\t\t\tpreset_id=" . $db->real_escape_string($this->get_preset()->get_id()) . ",\n\t\t\t\t\t\tvalid=" . $db->real_escape_string($this->get_valid()) . ",\n\t\t\t\t\t\tmember='" . $db->real_escape_string($this->get_member(true, "|")) . "',\n\t\t\t\t\t\tcorrectable='" . $db->real_escape_string($this->get_correctable()) . "',\n\t\t\t\t\t\trecorder='" . $db->real_escape_string($this->get_recorder()) . "'\n\t\t\t\t\tWHERE id = " . $db->real_escape_string($this->get_id());
         // execute
         $db->query($sql);
         // write rights
         try {
             $this->get_rights()->write_db($this->get_id());
         } catch (Exception $e) {
             throw new Exception('DbActionUnknown', $e->getCode());
         }
     } else {
         // error
         $errno = $GLOBALS['Error']->error_raised('DbActionUnknown', 'write_protocol', $action);
         throw new Exception('DbActionUnknown', $errno);
     }
     // close db
     $db->close();
 }
开发者ID:BackupTheBerlios,项目名称:judointranet,代码行数:48,代码来源:class.Protocol.php

示例7: check_preset

 /**
  * check_preset checks if the given id exists in db and is of $table
  * 
  * @param int $id id of the preset
  * @param string $table tablename the id is associated with
  * @return bool true if id exists and match $table, false otherwise
  */
 public static function check_preset($id, $table)
 {
     // get db-object
     $db = Db::newDb();
     // prepare sql
     $sql = "SELECT p.id,p.table\n\t\t\t\tFROM preset AS p\n\t\t\t\tWHERE id={$id}\n\t\t\t\tAND p.table='{$table}'";
     // execute
     $result = $db->query($sql);
     if ($result->num_rows == 0) {
         return false;
     } else {
         return true;
     }
 }
开发者ID:BackupTheBerlios,项目名称:judointranet,代码行数:21,代码来源:class.Preset.php

示例8: get_movements

 /**
  * get_movements returns the htmlstring of the movements
  * 
  * @param object $inventory the inventory object
  * @return string html of the movement list
  */
 private function get_movements($inventory)
 {
     // get id
     $id = $inventory->get_id();
     // get preset
     $preset = $inventory->get_preset();
     // get fields
     $fields = $preset->get_fields();
     // get db-object
     $db = Db::newDb();
     // prepare sql-statement
     $sql = "SELECT u.name,m.id,m.date_time\n\t\t\t\tFROM user AS u, inventory_movement AS m\n\t\t\t\tWHERE m.action = 'taken'\n\t\t\t\tAND m.inventory_id = {$id}\n\t\t\t\tAND u.id = m.user_id\n\t\t\t\tORDER BY m.date_time DESC";
     // execute
     $result = $db->query($sql);
     $movements = array();
     while (list($name, $movement_id, $date_time) = $result->fetch_array(MYSQL_NUM)) {
         // smarty
         $movements[] = array('href' => 'inventory.php?id=movement&mid=' . $movement_id, 'title' => parent::lang('class.InventoryView#get_movements#date#title'), 'content' => date('d.m.Y', strtotime($date_time)), 'name' => $name);
     }
     // return
     return $movements;
 }
开发者ID:BackupTheBerlios,项目名称:judointranet,代码行数:28,代码来源:class.InventoryView.php

示例9: new_row

 /**
  * new_row inserts a new row in $table
  * 
  * @param string $table table to insert row
  * @return string HTML-string for the form or message
  */
 private function new_row($table)
 {
     // prepare return
     $return = '';
     // get url-parameters
     $link = '';
     if ($table == 'defaults') {
         $link = 'administration.php?id=' . $this->get('id');
     } else {
         $link = 'administration.php?id=' . $this->get('id') . '&field=' . $table;
     }
     // get db-object
     $db = Db::newDb();
     // prepare statement
     $sql = "SELECT * FROM {$table}";
     // execute
     $result = $db->query($sql);
     // table info
     $tinfo = $result->fetch_fields();
     // prepare form
     $form = new HTML_QuickForm2('new_' . $table, 'post', array('name' => 'new_' . $table, 'action' => $link . '&action=new'));
     // add datasource (valid = 1)
     $datasource['valid'] = 1;
     $form->addDataSource(new HTML_QuickForm2_DataSource_Array($datasource));
     // renderer
     $renderer = HTML_QuickForm2_Renderer::factory('default');
     $renderer->setOption('required_note', parent::lang('class.AdministrationView#new_row#form#requiredNote'));
     // get values and fields
     $i = 0;
     $fields = array();
     foreach ($tinfo as $col) {
         // check translation
         $translated_col = '';
         if (parent::lang('class.AdministrationView#tableRows#name#' . $col->name) != "class.AdministrationView#tableRows#name#{$col->name} not translated") {
             $translated_col = parent::lang('class.AdministrationView#tableRows#name#' . $col->name);
         } else {
             $translated_col = $col->name;
         }
         // check id
         if ($col->name != 'id') {
             // col->type
             // 252 = text, 253 = varchar; 1 = tinyint(boolean); 3 = int
             // add field
             $field = null;
             // check category
             if ($col->name == 'category') {
                 // get options
                 $cat_sql = "SELECT id,name FROM category WHERE valid=1";
                 $cat_result = $db->query($cat_sql);
                 $options = array('--');
                 while (list($id, $name) = $cat_result->fetch_array(MYSQL_NUM)) {
                     $options[$id] = $name;
                 }
                 // select
                 $field = $form->addElement('select', $col->name, array());
                 $field->setLabel($translated_col . ':');
                 // load options
                 $field->loadOptions($options);
                 // add rules
                 if ($table == 'defaults') {
                     $field->addRule('required', parent::lang('class.AdministrationView#new_row#rule#requiredSelect'));
                     $field->addRule('callback', parent::lang('class.AdministrationView#new_row#rule#checkSelect'), array($this, 'callback_check_select'));
                 }
             } else {
                 // check type
                 if ($col->type == 252) {
                     // textarea
                     $field = $form->addElement('textarea', $col->name, array());
                     $field->setLabel($translated_col . ':');
                     // add rules
                     $field->addRule('regex', parent::lang('class.AdministrationView#new_row#rule#regexp.allowedChars') . ' [' . $_SESSION['GC']->get_config('textarea.desc') . ']', $_SESSION['GC']->get_config('textarea.regexp'));
                     // required
                     if ($table == 'defaults') {
                         $field->addRule('required', parent::lang('class.AdministrationView#new_row#rule#required'));
                     }
                 } elseif ($col->type == 253 || $col->type == 3) {
                     // input
                     $field = $form->addElement('text', $col->name, array());
                     $field->setLabel($translated_col . ':');
                     // add rules
                     $field->addRule('regex', parent::lang('class.AdministrationView#new_row#rule#regexp.allowedChars') . ' [' . $_SESSION['GC']->get_config('textarea.desc') . ']', $_SESSION['GC']->get_config('textarea.regexp'));
                     // required
                     if ($table == 'defaults') {
                         $field->addRule('required', parent::lang('class.AdministrationView#new_row#rule#required'));
                     }
                 } elseif ($col->type == 1) {
                     // input
                     $field = $form->addElement('checkbox', $col->name, array());
                     $field->setLabel($translated_col . ':');
                 }
             }
         }
         // increment field-counter
         $i++;
//.........这里部分代码省略.........
开发者ID:BackupTheBerlios,项目名称:judointranet,代码行数:101,代码来源:class.AdministrationView.php

示例10: movement_last_values

 /**
  * movement_last_values returns an array containing the field values
  * of the last movement 
  * 
  * @return array array contains tht field values of the last movement
  */
 public function movement_last_values()
 {
     // get db-object
     $db = Db::newDb();
     // get last movements
     $id = Inventory::movement_last_row($db, $this->get_id(), 'id', 2);
     // prepare sql-statement
     $sql = "SELECT v.field_id,v.value\n\t\t\t\tFROM value AS v\n\t\t\t\tWHERE table_name = 'inventory_movement'\n\t\t\t\tAND table_id = " . $id[1];
     // execute
     $result = $db->query($sql);
     // fetch result
     $return = array();
     while (list($field_id, $value) = $result->fetch_array(MYSQL_NUM)) {
         $return['inventory-' . $field_id] = $value;
     }
     // return
     return $return;
 }
开发者ID:BackupTheBerlios,项目名称:judointranet,代码行数:24,代码来源:class.Inventory.php

示例11: user

 /**
  * user controles the actions for usersettings
  * 
  * @return string the html-string of usersettings-page
  */
 private function user()
 {
     // smarty-template
     $sUserPasswd = new JudoIntranetSmarty();
     // prepare return
     $return = '';
     // check login
     if ($_SESSION['user']->get_loggedin()) {
         // smarty
         $sUserPasswd->assign('pagecaption', parent::lang('class.MainView#user#caption#general') . ' ' . $_SESSION['user']->get_userinfo('name'));
         // check action
         if ($this->get('action') == 'passwd') {
             // smarty
             $sUserPasswd->assign('section', parent::lang('class.MainView#user#caption#passwd'));
             // prepare form
             $form = new HTML_QuickForm2('passwd', 'post', array('name' => 'passwd', 'action' => 'index.php?id=user&action=passwd'));
             // add elementgroup
             $passwd = $form->addElement('group', 'password', array());
             // add fields
             $passwd1 = $passwd->addElement('password', 'password1', array());
             $passwd2 = $passwd->addElement('password', 'password2', array());
             // add label
             $passwd->setLabel(parent::lang('class.MainView#user#passwd#label') . ':');
             // submit-button
             $form->addSubmit('submit', array('value' => parent::lang('class.MainView#user#passwd#submitButton')));
             // renderer
             $renderer = HTML_QuickForm2_Renderer::factory('default');
             $renderer->setOption('required_note', parent::lang('class.MainView#user#form#requiredNote'));
             // add rules
             $passwd->addRule('required', parent::lang('class.MainView#user#rule#required'));
             $passwd->addRule('callback', parent::lang('class.MainView#user#rule#checkPasswd'), array($this, 'callback_check_passwd'));
             // validate
             if ($form->validate()) {
                 // get values
                 $data = $form->getValue();
                 // get db-object
                 $db = Db::newDb();
                 // prepare sql-statement
                 $sql = "UPDATE user\n\t\t\t\t\t\t\tSET password='" . md5($data['password']['password1']) . "'\n\t\t\t\t\t\t\tWHERE id=" . $_SESSION['user']->get_id();
                 // execute statement
                 $result = $db->query($sql);
                 // smarty message
                 $sUserPasswd->assign('message', parent::lang('class.MainView#user#validate#passwdChanged'));
             } else {
                 // smarty form and return
                 $sUserPasswd->assign('form', $form->render($renderer));
             }
             return $sUserPasswd->fetch('smarty.user.passwd.tpl');
         } else {
             return 'default content';
         }
     } else {
         // not authorized
         $errno = $GLOBALS['Error']->error_raised('NotAuthorized', 'entry:' . $this->get('id'), $this->get('id'));
         $GLOBALS['Error']->handle_error($errno);
         return $GLOBALS['Error']->to_html($errno);
     }
 }
开发者ID:BackupTheBerlios,项目名称:judointranet,代码行数:63,代码来源:class.MainView.php

示例12: listCorrections

 /**
  * listCorrections returns an array of all corrections of this protocol
  * 
  * @param int $id id of the protocol to be checked
  * @return array list of all corrections of the given protocol id
  */
 public static function listCorrections($pid)
 {
     // get db-object
     $db = Db::newDb();
     // prepare sql-statement
     $sql = "SELECT *\n\t\t\t\tFROM protocol_correction\n\t\t\t\tWHERE pid = " . $pid;
     // execute
     $result = $db->query($sql);
     // get result
     $corrections = array();
     while ($correction = $result->fetch_array(MYSQL_ASSOC)) {
         $corrections[] = $correction;
     }
     // close db
     $db->close();
     // return
     return $corrections;
 }
开发者ID:BackupTheBerlios,项目名称:judointranet,代码行数:24,代码来源:class.ProtocolCorrection.php


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