db_mysqli::query PHP Méthode

query() public méthode

执行查询 返回数据集
public query ( string $str ) : mixed
$str string sql指令
Résultat mixed
    public function query($str)
    {
        $this->initConnect(false);
        if (!$this->_linkID) {
            return false;
        }
        $this->queryStr = $str;
        //释放前次的查询结果
        if ($this->queryID) {
            $this->free();
        }
        // N('db_query',1);
        // 记录开始执行时间
        // G('queryStartTime');
        $this->queryID = $this->_linkID->query($str);
        // 对存储过程改进
        if ($this->_linkID->more_results()) {
            while (($res = $this->_linkID->next_result()) != NULL) {
                $res->free_result();
            }
        }
        $this->debug();
        if (false === $this->queryID) {
            $this->error();
            return false;
        } else {
            if (0 === stripos($str, 'call')) {
                // 存储过程查询支持
                $this->close();
                $this->linkID = array();
            }
            $this->numRows = $this->queryID->num_rows;
            $this->numCols = $this->queryID->field_count;
            return $this->getAll();
        }
    }

Usage Example

Exemple #1
0
 echo '<b style="color:#0A0">[Success]</b></p>';
 echo '<p>Updating .htaccess file ';
 if (!file_exists(FORUM_ROOT . '/htaccess.tpl')) {
     echo '<b style="color:#F00">[Failed]</b></p></body></html>';
     die;
 }
 $data = file_get_contents(FORUM_ROOT . '/htaccess.tpl');
 $basepath = str_replace('static/install.php', '', $_SERVER['REQUEST_URI']);
 $data = str_replace('<baseurl>', $basepath, $data);
 @file_put_contents(FORUM_ROOT . '/.htaccess', $data);
 if (!strstr(file_get_contents(FORUM_ROOT . '/.htaccess'), $basepath)) {
     echo '<b style="color:#F00">[Failed]</b></p></body></html>';
     die;
 }
 echo '<b style="color:#0A0">[Success]</b></p>';
 $db->query('TRUNCATE TABLE `#^config`') or error('Failed to wipe config', __FILE__, __LINE__, $db->error());
 set_config('board_title', $_POST['config']['board_title']);
 set_config('admin_email', $_POST['config']['admin_email']);
 set_config('announcement_text', '');
 set_config('announcement_enable', 0);
 set_config('default_user_group', 3);
 set_config('censoring', '');
 set_config('footer_text', '');
 $db->query('TRUNCATE TABLE `#^users`') or error('Failed to wipe users table', __FILE__, __LINE__, $db->error());
 $db->query('INSERT INTO `#^users`(id,username,group_id,timezone) VALUES(0,\'Guest\',2,0)') or error('Failed to create guest user', __FILE__, __LINE__, $db->error());
 $db->query('UPDATE `#^users` SET id=0 WHERE username=\'Guest\'') or error('Failed to zero ID of guest user', __FILE__, __LINE__, $db->error());
 $db->query('INSERT INTO `#^users`(username,password,email,registered,registration_ip,group_id,last_visit,timezone) VALUES(\'' . $db->escape($_POST['username']) . '\',\'' . futurebb_hash($_POST['pwd1']) . '\',\'' . $db->escape($_POST['email']) . '\',' . time() . ',\'' . $db->escape($_SERVER['REMOTE_ADDR']) . '\',1,' . time() . ',0)') or error('Failed to create admin user', __FILE__, __LINE__, $db->error());
 $db->query('TRUNCATE TABLE `#^user_groups') or error('Failed to wipe user groups', __FILE__, __LINE__, $db->error());
 $db->query('INSERT INTO `#^user_groups`(g_permanent,g_guest_group,g_name,g_title,g_admin_privs,g_mod_privs,g_edit_posts,g_delete_posts,g_signature) VALUES(1,0,\'Administrators\',\'Administrator\',1,1,1,1,1)') or error('Failed to create admin user group', __FILE__, __LINE__, $db->error());
 $db->query('INSERT INTO `#^user_groups`(g_permanent,g_guest_group,g_name,g_title,g_admin_privs,g_mod_privs,g_edit_posts,g_delete_posts,g_signature) VALUES(1,1,\'Guests\',\'Guest\',0,0,0,0,0)') or error('Failed to create guest user group', __FILE__, __LINE__, $db->error());
 $db->query('INSERT INTO `#^user_groups`(g_permanent,g_guest_group,g_name,g_title,g_admin_privs,g_mod_privs,g_edit_posts,g_delete_posts,g_signature) VALUES(1,0,\'Members\',\'Member\',0,0,1,1,1)') or error('Failed to create member user group', __FILE__, __LINE__, $db->error());