使用数组和mysqli仅选择一个表行

时间:2014-01-20 17:34:27

标签: php mysqli

下表和函数属于PHP MySQL数据库集成(https://github.com/blueimp/jQuery-File-Upload/wiki/PHP-MySQL-database-integration)。该函数显示名为“files”的表的所有字段。我想用usr字段扩展表,因为之后,我想只显示与我之前将通过变量传递的用户匹配的行。我的步骤(测试)我用usr字段扩展表,然后进入('admin')usr,并尝试使用这段代码:

$this->options['db_table'].'` WHERE `usr`=admin';  

但是什么都不显示......。任何想法?

扩展表(决赛桌):

CREATE TABLE `files` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `usr` varchar(255) DEFAULT NULL
  `name` varchar(255) DEFAULT NULL,
  `size` int(11) DEFAULT NULL,
  `type` varchar(255) DEFAULT NULL,
  `url` varchar(255) DEFAULT NULL,
  `title` varchar(255) DEFAULT NULL,
  `description` text,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

PHP函数:

<?php
$options = array(
    'delete_type' => 'POST',
    'db_host' => 'localhost',
    'db_user' => 'root',
    'db_pass' => '',
    'db_name' => 'example',
    'db_table' => 'files'
);

….

protected function set_additional_file_properties($file) {
        parent::set_additional_file_properties($file);
        if ($_SERVER['REQUEST_METHOD'] === 'GET') {
            $sql = 'SELECT `id`, `type`, `title`, `description` FROM `' 
            .$this->options['db_table'].'` WHERE `name`=?'; 
            $query = $this->db->prepare($sql);
            $query->bind_param('s', $file->name);
            $query->execute();
            $query->bind_result(
                $id,
                $type,
                $title,
                $description
            );
            while ($query->fetch()) {
                $file->id = $id;
                $file->type = $type;
                $file->title = $title;
                $file->description = $description;
            }
        }

0 个答案:

没有答案