Zend Framework mysql query return server 500 error
I use Zend Framework. Code
$this->_db->query("INSERT INTO blog SET ....")
returns 500 error.开发者_如何学编程 But if I replace it to
mysql_query("INSERT INTO blog SET ....")
all ok. What can be wrong?
Are you sure $this->_db
is what you expect it to be?
If you're using the default ErrorController, setting
resources.frontController.params.displayExceptions = 1
in your /application/config/application.ini should give you a backtrace of the error.
Also, if it really is just the query generating an exception you can wrap it in a try/catch and see the exception.
try {
$this->_db->query("INSERT INTO blog SET ....");
} catch(Exception $e) {
echo $e->getMessage();
}
I think your SQL syntax is wrong. Correct syntax:
INSERT INTO table (fields) VALUES (values)
EDIT: Oh sorry just read that your mysql_query() is working with the same SQL. As someone else recommended I'd recommend checking the logs.
Most certainly your $this->_db
is not an instance of Zend_Db_Adapter_Abstract :) Even more it may be NULL ;)
I had the same issue with a select statement in Zend. Simply adding a try..catch block around the $this->fetchRow($select) line solved the issue. Curiously, there were no exceptions caught..!!
精彩评论