【发布时间】:2011-03-05 09:30:20
【问题描述】:
我从在 Flash Builder 4 中创建的 Flash 应用返回了一个数组。
我有一个服务设置,可以成功查询并从数据库中取回数据,但是更新脚本正在生成未定义属性错误。
我仍在学习 PHP 和 Flash Builder,但不完全理解 $this-> 命令的作用。
如果有人能指出这个脚本哪里出了问题,它基本上只是由 Flash Builder 生成的,不是我自己开发的,我会很感激吗?
另外,如果有人可以向我解释 $this-> 那也太棒了?
我以前见过它们,但后来我看到脚本做同样的事情但不使用它们,那么这是一种旧的做事方式吗?
非常感谢任何人提供的任何意见。
更新了完整的 PHP 代码。
产生的错误。
[2010 年 6 月 18 日 13:01:37] PHP 通知:未定义属性:C:\wamp\www\Coradia-175105-debug\services\tbltrustservice.php 中的 stdClass::$inst_code 第 48 行
[18-Jun-2010 13:01:37] PHP 注意:未定义的属性:C:\wamp\www\Coradia-175105-debug\services\tbltrustservice.php 中的 stdClass::$trust_name 第 48 行
[2010 年 6 月 18 日 13:01:38] PHP 通知:未定义属性:C:\wamp\www\Coradia-175105-debug\services\tbltrustservice.php 中的 stdClass::$trust_code 第 48 行
[2010 年 6 月 18 日 13:01:38] PHP 通知:未定义属性:C:\wamp\www\Coradia-175105-debug\services\tbltrustservice.php 中的 stdClass::$trust_key 第 48 行
<?php
//reroute errors to get rid of that annoying CHANNEL DISCONNECTED message.
ini_set('error_log', 'errorLog.txt');
ini_set('html_errors', '0');
ini_set('display_errors', '0');
ini_set('log_errors', '1');
class tbltrustservice {
public $connection;
public function connect() {
$this->connection = mysqli_connect("ahoey-1:3306", "<Username Removed For StackOverflow>", "<Password Removed for StackOverflow>", "enabmodules") or die(mysqli_connect_error());
}
public function getAllItems($search) {
$this->connect();
if ($search=="") {
$sql = "SELECT * FROM tbltrust";
} else {
$sql = 'SELECT * FROM tbltrust WHERE trust_name LIKE \'%'.mysql_escape_string($search).'%\' OR trust_code LIKE \''.mysql_escape_string($search).'%\' OR inst_code LIKE \'%'.mysql_escape_string($search).'%\'';
}
$result = mysqli_query($this->connection, $sql) or die('Query failed: ' . mysqli_error($this->connection));
$rows = array();
while ($row = mysqli_fetch_object($result)) {
$rows[] = $row;
}
mysqli_free_result($result);
mysqli_close($this->connection);
return $rows;
}
public function updateItem($item) {
// TODO Auto-generated method stub
// Update an existing record in the database and return the item
// Sample code \'
$this->connect();
$sql = "UPDATE tbltrust SET inst_code = '$item->inst_code', trust_name = '$item->trust_name', trust_code = '$item->trust_code' WHERE trust_key = '$item->trust_key'";
mysqli_query($this->connection, $sql) or die('Query failed: ' . mysqli_error($this->connection));
mysqli_close($this->connection);
}
/*
public function updateItem($item) {
$stmt = mysqli_prepare($this->connection, "UPDATE $this->tablename SET trust_code=?, trust_name=?, inst_code=? WHERE trust_key=?");
$this->throwExceptionOnError();
mysqli_stmt_bind_param($stmt, 'sssi', $item->trust_code, $item->trust_name, $item->inst_code, $item->trust_key);
$this->throwExceptionOnError();
mysqli_stmt_execute($stmt);
$this->throwExceptionOnError();
mysqli_stmt_free_result($stmt);
mysqli_close($this->connection);
}
*/
public function getItem($itemID) {
// TODO Auto-generated method stub
// Return a single record from the database and return the item
// Sample code
/*
$this->connect();
$itemID = mysqli_real_escape_string($this->connection, $itemID);
$sql = "SELECT * FROM books where itemID=$itemID";
$result = mysqli_query($this->connection, $sql) or die('Query failed: ' . mysqli_error($this->connection));
$rows = array();
while ($row = mysqli_fetch_object($result)) {
$rows[] = $row;
}
mysqli_free_result($result);
mysqli_close($this->connection);
return $rows;
*/
}
public function createItem($item) {
// TODO Auto-generated method stub
// Insert a new record in the database using the parameter and return the item
// Sample code
/*
$this->connect();
$sql = "INSERT INTO books (title, au_first_name, au_last_name)
VALUES ('$item->title','$item->au_first_name','$item->au_last_name')";
mysqli_query($this->connection, $sql) or die('Query failed: ' . mysqli_error($this->connection));
$autoid= mysqli_insert_id($this->connection);
mysqli_close($this->connection);
return $autoid;
*/
}
/*
public function updateItem($item) {
$stmt = mysqli_prepare($this->connection, "UPDATE tbltrust SET trust_code=?, trust_name=?, inst_code=? WHERE trust_key=?");
$this->throwExceptionOnError();
mysqli_stmt_bind_param($stmt, 'sssi', $item->trust_code, $item->trust_name, $item->inst_code, $item->trust_key);
$this->throwExceptionOnError();
mysqli_stmt_execute($stmt);
$this->throwExceptionOnError();
mysqli_stmt_free_result($stmt);
mysqli_close($this->connection);
} */
public function deleteItem($itemID) {
// TODO Auto-generated method stub
// Delete a record in the database
// Sample code
/*
$this->connect();
$itemID = mysqli_real_escape_string($this->connection, $itemID);
$sql = "DELETE FROM books WHERE itemID = $itemID";
mysqli_query($this->connection, $sql) or die('Query failed: ' . mysqli_error($this->connection));
mysqli_close($this->connection);
*/
}
public function count() {
// TODO Auto-generated method stub
// Return the number of items in your array of records
// Sample code
/*
$this->connect();
$sql = "SELECT * FROM books";
$result = mysqli_query($this->connection, $sql) or die('Query failed: ' . mysqli_error($this->connection));
$rec_count = mysqli_num_rows($result);
mysqli_free_result($result);
mysqli_close($this->connection);
return $rec_count;
*/
}
public function getItems_paged($startIndex, $numItems) {
// TODO Auto-generated method stub
// Return a page of records as an array from the database for this startIndex
// Sample code
/*
$this->connect();
$startIndex = mysqli_real_escape_string($this->connection, $startIndex);
$numItems = mysqli_real_escape_string($this->connection, $numItems);
$sql = "SELECT * FROM books LIMIT $startIndex, $numItems";
$result = mysqli_query($this->connection, $sql) or die('Query failed: ' . mysqli_error($this->connection));
$rows = array();
while ($row = mysqli_fetch_object($result)) {
$rows[] = $row;
}
mysqli_free_result($result);
mysqli_close($this->connection);
return $rows;
*/
}
}
?>
【问题讨论】:
-
您能否添加确切的错误消息以及它们出现在哪些行中?
-
尽快了解您编码的语言。巧合的编程比正确的编程要付出更多的努力。
标签: php