【发布时间】:2014-12-04 08:21:53
【问题描述】:
我想从我的 android 应用程序调用 WAMP 服务器中的 php 文件。然后预计 php 文件将连接到 WAMP sql 数据库。我已经编写了以下代码。由于我计划上传的数据格式,我需要如下结构。
所以现在的问题是,只要我在 uploadRequest 方法中创建一个 ConfigGraphsDAO 对象,fileId 就会返回 null。但是如果我评论该行,fileId 将返回为 2。有人可以向我解释我做错了什么吗?非常感谢
从我的应用程序调用的 php 文件名为 UploadController.php,如下所示
require_once 'config.php';
require_once 'DAO.php';
$fileId=1;
class UploadController {
private static function uploadRequest() {
global $config;
$configGraphDAO = new ConfigGraphsDAO();
$fileName = (isset($_POST[self::$PARAM_FILE_NAME])) ? $_POST[self::$PARAM_FILE_NAME] : null;
$GLOBALS['fileId']=$GLOBALS['fileId']+1;
echo self::$PARAM_FILE_ID . "=" . $GLOBALS['fileId'];
}
}
ConfigGraphsDAO.php 如下。
class ConfigGraphsDAO extends DAO{
//I plan to do something here. But right now its all empty
}
DAO.php如下
abstract class DAO {
public function __construct() {
$this->connect();
}
private function connect() {
global $config;
$this->con = mysql_connect($config["DB_HOST"], $config["DB_USER"], $config["DB_PASSWORD"],$config["DB_NAME"] );
if (!$this->con) {
throw new Exception("Failed to connect to database." . mysql_error());
}
}
}
config.php如下。
$config = array();
$config["DB_HOST"] = "localhost"; //"http://172.26.191.215"; //"localhost"; //
$config["DB_NAME"] = "ocean";
$config["DB_USER"] = "root";
$config["DB_PASSWORD"] = "";
$config["UPLOAD_DIR"] = "context_repo";
$config["DASH_SERVER_ADDR"] = "http://172.26.191.215/ocean";
【问题讨论】:
-
$PARAM_FILE_NAME定义在哪里? -
我认为你需要阅读关于Abstract classes主题的手册,主要是这个
Classes defined as abstract may not be instantiated。还有这个When inheriting from an abstract class, all methods marked abstract in the parent's class declaration must be defined by the child;