0

为什么这个数据库查询失败?在我的 CentOS 中。

错误/异常:

"Notice: Undefined variable: table in /var/www/html/-manager/application/controllers/IndexController.php on line 37 Fatal error: Call to a member function getAdapter() on a non-object in /var/www/html/-manager/application/controllers/IndexController.php on line 37 Warning: Unknown: write failed: No space left on device (28) in Unknown on line 0 Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/var/lib/php/session) in Unknown on line 0

磁盘空间?:

$ df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_demo-lv_root
                       50G   47G     0 100% /
tmpfs                 3.9G     0  3.9G   0% /dev/shm
/dev/sda1             485M   47M  413M  11% /boot
/dev/mapper/vg_demo-lv_home
                      170G  200M  161G   1% /home

调用为:

    $rows = new Application_Model_Clients();  // PASS
    $dbsession = $rows->give_sessions("test"); // FAILS

库存为:

mysql> select username,password from sh_operator;
+----------+----------+
| username | password |
+----------+----------+
| test     | 1234567  |
+----------+----------+
1 rows in set (0.00 sec)

mysql> 


<?php

class Application_Model_Clients extends Zend_Db_Table {

  protected $_name = 'web145-mydb.sh_operator';

  public function addRecord($post) {
    $encrypted = mt_rand();
    $value = array(
        'email'       => $post->email,
    );
    return $this->insert($value);
  }

  public function search($zip) {
    $result = $this->fetchRow("zip =" . $zip);
    return $result->toArray();
  }

  public function give_sessions($input) {
    Zend_Debug::dump($input); // PASS test
    echo "alive 0 "; // PASS
    $result = $this->fetchRow("username ='" . $input . "'");
    echo "alive 1 "; // fails
    exit;
    return $result->toArray();
  }

}

?>
4

2 回答 2

0

看起来您的 sql forgive_sessions()可能会以很多引号结尾"username ='" . "test" . "'"

您可能会考虑让自己轻松一点,只需使用提供的select()对象语法来为您处理引用。如果你不这样做,fetchRow()只会做一个select() 。

public function give_sessions($input) {
    $select = $this->select();
    $select->where('username = ?', $input);
    $result = $this->fetchRow($select);
    return $result->toArray();
  }

使用 select() 还可以在您构建查询的方式上提供很大的灵活性。

您可能希望在控制器操作中使用一些代码来测试您当前的适配器配置,例如:

$table = new Application_Model_Clients();
Zend_Debug::dump($table->getAdapter()->listTables(), 'Adapter Table List');

这将回显适配器有权访问的表数组。

于 2012-10-27T09:04:24.767 回答
0

对于带有“-”的数据库名称,您可能需要使用反引号将其正确分配给适配器。

   protected $_name = '`web145-mydb`.sh_operator';

异常表明您没有剩余磁盘空间。清理一些空间,这应该可以解决问题。

于 2012-10-27T16:53:24.623 回答