我有下面這段PHP腳本的問題:PHP類沒有響應
<?php
abstract class root {
protected $con;
protected $sql;
protected $query;
protected $row;
protected function __construct__() {
require_once("db.settings.php");
$this->con = mysql_connect(DB_HOST, DB_USER, DB_PASS) or die(mysql_error($this->con));
mysql_query("SET NAMES UTF8", $this->con) or die(mysql_error($this->con));
mysql_close($this->con);
mysql_select_db(DB_NAME, $this->con);
}
protected function __destruct__() {
mysql_close($this->con);
unset($this->con);
}
}
class users extends root {
private $h;
public function __construct__() {
parent::__construct__();
}
public function __destruct__() {
parent::__destruct__();
}
public function register($uname, $pass, $mail, $name) {
$this->hash = sha1($uname . md5($pass) . $name);
$this->sql = "INSERT INTO users (user, pass, mail, name, hash) VALUES ($uname, $pass, $mail, $name, $this->hash)";
mysql_query($this->sql, $this->con) or die(mysql_error($this->con));
mysql_close($this->con);
return true;
}
public function login($uname, $pass) {
$this->sql = "SELECT * FROM users WHERE user = $uname AND pass = " . md5($pass);
mysql_query($this->sql, $this->con) or die(mysql_error($this->con));
if(mysql_num_rows !== 1){
mysql_close($this->con);
return false;
} else {
setcookie("who", $uname, time() + 3600);
$this->h = md5($pass);
setcookie("token", $this->h, time() + 3600);
$this->h = sha1($uname . md5($pass));
setcookie("hash", $uname, time() + 3600);
return true;
}
}
public function logout() {
if(isset($_COOKIE['who']) && isset($_COOKIE['token']) && isset($_COOKIE['hash']) && $_COOKIE['hash'] == sha1($_COOKIE['who'] . $_COOKIE['token'])) {
setcookie("who", $uname, time() - 1);
setcookie("token", $uname, time() - 1);
setcookie("hash", $uname, time() - 1);
return true;
} else {
setcookie("who", $uname, time() - 1);
setcookie("token", $uname, time() - 1);
setcookie("hash", $uname, time() - 1);
return false;
}
}
public function check() {
if(isset($_COOKIE['who']) && isset($_COOKIE['token']) && isset($_COOKIE['hash']) && $_COOKIE['hash'] == sha1($_COOKIE['who'] . $_COOKIE['token'])) {
return true;
} else {
return false;
}
}
}
class iPhone extends root {
private $hash;
public $content = array();
private $j = 0;
public function __construct__() {
parent::__construct__();
}
public function __destruct__() {
parent::__destruct__();
}
public function registerIphone() {
# implented later
$this->hash = md5(time);
$this->sql = "UPDATE users SET phoneid = " . $this->hash . " WHERE user = " . $_COOKIE['who'];
mysql_query($this->sql, $this->con) or die(mysql_error($this->con));
setcookie("phoneid", $this->hash, 1314000);
return true;
}
public function checkIphone() {
# implented later
$this->sql = "SELECT * FROM users WHERE phoneid = " . $_COOKIE['phoneid'] . " LIMIT 1";
if(mysql_query($this->sql, $this->con)) {
return true;
} else {
return false;
}
}
public function deleteIphone($who) {
# implented later
$this->sql = "UPDATE users SET phoneid = '' WHERE user = $who";
if(mysql_query($this->sql, $this->con)) {
return true;
} else {
return false;
}
}
public function showContent($what) {
$this->sql = "SELECT * FROM content WHERE articleName = " . $what . " AND media = Handheld";
$this->query = mysql_query($this->sql, $this->con) or die(mysql_error($this->con));
while($this->row = mysql_fetch_array($this->query)) {
$content[$j]['id'] = $row['id'];
$content[$j]['date'] = $row['date'];
$content[$j]['articleName'] = $row['articleName'];
$content[$j]['content'] = $row['content'];
$this->j++;
}
mysql_close($this->con);
return $this->content;
}
}
class contentManager extends root {
public $content = array();
private $j = 0;
public function __construct__() {
parent::__construct__();
}
public function __destruct__() {
parent::__destruct__();
}
public function showContent($what) {
$this->sql = "SELECT * FROM content WHERE articleName = $what AND media = Browser";
$this->query = mysql_query($this->sql, $this->con) or die(mysql_error($this->con));
while($this->row = mysql_fetch_array($this->query)) {
$content[$j]['id'] = $row['id'];
$content[$j]['date'] = $row['date'];
$content[$j]['articleName'] = $row['articleName'];
$content[$j]['content'] = $row['content'];
$this->j++;
}
mysql_close($this->con);
return $this->content;
}
public function editContent($id, $articlename, $content) {
$this->sql = "UPDATE content SET articleName = $articlename, content = $content WHERE id = $id";
mysql_query($this->sql, $this->con) or die(mysql_error($this->con));
return true;
}
public function deleteContent($id) {
$this->sql = "DELETE FROM content WHERE id = $id";
mysql_query($this->sql, $this->con) or die(mysql_error($this->con));
return true;
}
}
class map extends root {
private $j = 0;
private $key = "my google maps api key";
private $address;
private $helper;
private $page;
private $xml;
private $longitude;
private $latitude;
private $altitude;
public function __construct__() {
parent::__construct__();
}
public function __destruct__() {
parent::__destruct__();
}
public function getMarkers() {
$this->sql = "SELECT * FROM markers";
$this->query = mysql_query($this->sql, $this->con) or die(mysql_error($this->con));
while($this->row = mysql_fetch_array($this->query)) {
if($this->j < (mysql_num_rows($this->query) -1)){
print("['" . $this->row['address'] . "', " . $this->row['lat'] . ", " . $this->row['lng'] . ", 1],");
$this->j++;
} else {
print("['" . $this->row['address'] . "', " . $this->row['lat'] . ", " . $this->row['lng'] . ", 1]");
$this->j++;
}
}
}
public function setMarkers($addr) {
$this->helper = str_replace(" ", "+", $addr);
$this->helper = explode(",", $this->helper);
$this->address = "http://maps.google.com/maps/geo?q=$this->helper[0],+$this->helper[1],+$this->helper[2]&output=xml&key=$this->key";
$this->page = file_get_contents($this->address);
$this->xml = new SimpleXMLElement($this->page);
list($this->longitude, $this->latitude, $this->altitude) = explode(",", $xml->Response->Placemark->Point->coordinates);
echo $this->longitude . " :: " . $this->latitude;
}
public function deleteMarkers($id) {
/*
*** FUNCTION NOT YET IMPLENTED!
*/
}
}
?>
對於那些,誰不想讀源:我創建了一個抽象類,創建數據庫連接,那麼其他類,如登錄擴展它,使用父母數據庫連接。
的問題是,每當我創建一個類的實例,如:
$map = new map();
然後嘗試做一些與實例:
$map->setMarkers("");
什麼也沒有發生。毫無意義。沒有錯誤信息,也沒有輸出。
所有幫助將不勝感激!
您是否嘗試過調試?例如增加'print'語句來找出它卡住的地方? – 2010-11-13 22:45:20
是的,試圖從根和子類構造函數&&析構函數打印字符串。 – 2010-11-13 22:50:25