我正在尝试为录音室构建一个 CRUD 应用程序,使我们的客户能够在线预订会议。我已经设置了数据库,并且正在使用Flash builder 4.6创建一个服务调用,该调用创建工作室会话并将信息发布到数据库。我可以很好地将数据从MySQL拉取到数据网格,但是当我使用创建会话服务时,我收到一个错误,我似乎无法弄清楚.....>>>在我的php脚本的第123行中访问未定义的属性Session_Date。它还说我正在尝试将非对象传递给我的Session_Date->toString('YYYY-MM-DD hh:mm:ss')。为什么会这样,有人可以帮忙吗!!!!我已经搜索了论坛,但找不到直接答案。
这是我的PHP类:
class SessionsService {
var $username = "root";
var $password = "bossman1";
var $server = "localhost";
var $port = "3306";
var $databasename = "mydb";
var $tablename = "sessions";
var $connection;
/**
* The constructor initializes the connection to database. Everytime a request is
* received by Zend AMF, an instance of the service class is created and then the
* requested method is invoked.
*/
public function __construct() {
$this->connection = mysqli_connect(
$this->server,
$this->username,
$this->password,
$this->databasename,
$this->port
);
$this->throwExceptionOnError($this->connection);
}
/**
* Returns all the rows from the table.
*
* Add authroization or any logical checks for secure access to your data
*
* @return array
*/
public function getAllSessions() {
$stmt = mysqli_prepare($this->connection, "SELECT * FROM $this->tablename");
$this->throwExceptionOnError();
mysqli_stmt_execute($stmt);
$this->throwExceptionOnError();
$rows = array();
mysqli_stmt_bind_result($stmt, $row->Sessions_ID, $row->Session_Date, $row->Session_Time, $row->Requested_Engineer, $row->Time_In, $row->Time_Out);
while (mysqli_stmt_fetch($stmt)) {
$row->Session_Date = new DateTime($row->Session_Date);
$rows[] = $row;
$row = new stdClass();
mysqli_stmt_bind_result($stmt, $row->Sessions_ID, $row->Session_Date, $row->Session_Time, $row->Requested_Engineer, $row->Time_In, $row->Time_Out);
}
mysqli_stmt_free_result($stmt);
mysqli_close($this->connection);
return $rows;
}
/**
* Returns the item corresponding to the value specified for the primary key.
*
* Add authorization or any logical checks for secure access to your data
*
*
* @return stdClass
*/
public function getSessionsByID($itemID) {
$stmt = mysqli_prepare($this->connection, "SELECT * FROM $this->tablename where Sessions_ID=?");
$this->throwExceptionOnError();
mysqli_stmt_bind_param($stmt, 'i', $itemID);
$this->throwExceptionOnError();
mysqli_stmt_execute($stmt);
$this->throwExceptionOnError();
mysqli_stmt_bind_result($stmt, $row->Sessions_ID, $row->Session_Date, $row->Session_Time, $row->Requested_Engineer, $row->Time_In, $row->Time_Out);
if(mysqli_stmt_fetch($stmt)) {
$row->Session_Date = new DateTime($row->Session_Date);
return $row;
} else {
return null;
}
}
/**
* Returns the item corresponding to the value specified for the primary key.
*
* Add authorization or any logical checks for secure access to your data
*
*
* @return stdClass
*/
public function createSessions($item) {
$stmt = mysqli_prepare($this->connection, "INSERT INTO $this->tablename (Session_Date, Session_Time, Requested_Engineer, Time_In, Time_Out) VALUES (?, ?, ?, ?, ?)");
$this->throwExceptionOnError();
mysqli_stmt_bind_param($stmt, 'sssss', $item->Session_Date->toString('YYYY-MM-dd HH:mm:ss'), $item->Session_Time, $item->Requested_Engineer, $item->Time_In, $item->Time_Out);
$this->throwExceptionOnError();
mysqli_stmt_execute($stmt);
$this->throwExceptionOnError();
$autoid = mysqli_stmt_insert_id($stmt);
mysqli_stmt_free_result($stmt);
mysqli_close($this->connection);
return $autoid;
}
/**
* Updates the passed item in the table.
*
* Add authorization or any logical checks for secure access to your data
*
* @param stdClass $item
* @return void
*/
public function updateSessions($item) {
$stmt = mysqli_prepare($this->connection, "UPDATE $this->tablename SET Session_Date=?, Session_Time=?, Requested_Engineer=?, Time_In=?, Time_Out=? WHERE Sessions_ID=?");
$this->throwExceptionOnError();
if ($item->Session_Date == null)
$Session_Date = null;
else
$Session_Date = $item->Session_Date->toString('yyyy-MM-dd HH:mm:ss');
mysqli_stmt_bind_param($stmt, 'sssssi', $item->Session_Date->toString('YYYY-MM-dd HH:mm:ss'), $item->Session_Time, $item->Requested_Engineer, $item->Time_In, $item->Time_Out, $item->Sessions_ID);
$this->throwExceptionOnError();
mysqli_stmt_execute($stmt);
$this->throwExceptionOnError();
mysqli_stmt_free_result($stmt);
mysqli_close($this->connection);
}
/**
* Deletes the item corresponding to the passed primary key value from
* the table.
*
* Add authorization or any logical checks for secure access to your data
*
*
* @return void
*/
public function deleteSessions($itemID) {
$stmt = mysqli_prepare($this->connection, "DELETE FROM $this->tablename WHERE Sessions_ID = ?");
$this->throwExceptionOnError();
mysqli_stmt_bind_param($stmt, 'i', $itemID);
mysqli_stmt_execute($stmt);
$this->throwExceptionOnError();
mysqli_stmt_free_result($stmt);
mysqli_close($this->connection);
}
/**
* Returns the number of rows in the table.
*
* Add authorization or any logical checks for secure access to your data
*
*
*/
public function count() {
$stmt = mysqli_prepare($this->connection, "SELECT COUNT(*) AS COUNT FROM $this->tablename");
$this->throwExceptionOnError();
mysqli_stmt_execute($stmt);
$this->throwExceptionOnError();
mysqli_stmt_bind_result($stmt, $rec_count);
$this->throwExceptionOnError();
mysqli_stmt_fetch($stmt);
$this->throwExceptionOnError();
mysqli_stmt_free_result($stmt);
mysqli_close($this->connection);
return $rec_count;
}
/**
* Returns $numItems rows starting from the $startIndex row from the
* table.
*
* Add authorization or any logical checks for secure access to your data
*
*
*
* @return array
*/
public function getSessions_paged($startIndex, $numItems) {
$stmt = mysqli_prepare($this->connection, "SELECT * FROM $this->tablename LIMIT ?, ?");
$this->throwExceptionOnError();
mysqli_stmt_bind_param($stmt, 'ii', $startIndex, $numItems);
mysqli_stmt_execute($stmt);
$this->throwExceptionOnError();
$rows = array();
mysqli_stmt_bind_result($stmt, $row->Sessions_ID, $row->Session_Date, $row->Session_Time, $row->Requested_Engineer, $row->Time_In, $row->Time_Out);
while (mysqli_stmt_fetch($stmt)) {
$row->Session_Date = new DateTime($row->Session_Date);
$rows[] = $row;
$row = new stdClass();
mysqli_stmt_bind_result($stmt, $row->Sessions_ID, $row->Session_Date, $row->Session_Time, $row->Requested_Engineer, $row->Time_In, $row->Time_Out);
}
mysqli_stmt_free_result($stmt);
mysqli_close($this->connection);
return $rows;
}
/**
* Utility function to throw an exception if an error occurs
* while running a mysql command.
*/
private function throwExceptionOnError($link = null) {
if($link == null) {
$link = $this->connection;
}
if(mysqli_error($link)) {
$msg = mysqli_errno($link) . ": " . mysqli_error($link);
throw new Exception('MySQL Error - '. $msg);
}
}
}
?>
这是错误消息:
Reason: ( ! ) SCREAM: Error suppression ignored for ( ! ) Notice: Trying to get property of non-object in C:'wamp'www'Server_Test_Project'services'SessionsService1.php on line 123 Call Stack
Time Memory Function Location
1 0.0008 699024 {main}( ) ..'gateway.php:0 2 0.0465 2709608 Zend_Amf_Server->handle( ) ..'gateway.php:69 3 0.0539 3053728 Zend_Amf_Server->_handle( ) ..'Server.php:629 4 0.0592 3247600 Zend_Amf_Server->_dispatch( ) ..'Server.php:553 5 0.0636 3411240 Zend_Server_Reflection_Method->invokeArgs( ) ..'Server.php:359 6 0.0636 3411656 Zend_Server_Reflection_Function_Abstract->__call( ) ..'Server.php:359 7 0.0636 3412072 call_user_func_array( ) ..'Abstract.php:380 8 0.0636 3412552 SessionsService1->createSessions( ) ..'Abstract.php:0
( ! ) SCREAM: Error suppression ignored for ( ! ) Fatal error: Call to a member function toString() on a non-object in C:'wamp'www'Server_Test_Project'services'SessionsService1.php on line 123 Call Stack
Time Memory Function Location
1 0.0008 699024 {main}( ) ..'gateway.php:0 2 0.0465 2709608 Zend_Amf_Server->handle( ) ..'gateway.php:69 3 0.0539 3053728 Zend_Amf_Server->_handle( ) ..'Server.php:629 4 0.0592 3247600 Zend_Amf_Server->_dispatch( ) ..'Server.php:553 5 0.0636 3411240 Zend_Server_Reflection_Method->invokeArgs( ) ..'Server.php:359 6 0.0636 3411656 Zend_Server_Reflection_Function_Abstract->__call( ) ..'Server.php:359 7 0.0636 3412072 call_user_func_array( ) ..'Abstract.php:380 8 0.0636 3412552 SessionsService1->createSessions( ) ..'Abstract.php:0
要解决此问题,请打开 PHP ini 并更改
error_reporting = E_ALL
该声明中可能会有E_STRICT。Zend不严格合规:)
祝你好运。。。
刚刚发现在 PHP 5.4 中,默认情况下启用e_strict,因此error_reporting应该是这样的:error_reporting = E_ALL & ~E_STRICT