为什么此数据库查询失败?在我的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();
}
}
?>
答案 0 :(得分:1)
看起来你的give_sessions()
的sql很可能会以多个引号"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');
将回显出适配器可以访问的表的数组。
答案 1 :(得分:1)
对于带有“ - ”的数据库名称,您可能需要使用反引号将其正确分配给适配器。
protected $_name = '`web145-mydb`.sh_operator';
该异常表明您没有剩余磁盘空间。清理一些应该解决问题的空间。