嗨,大家好,我有以下代碼:PHP OOP取回陣列從數據庫和MySQL
$this->db->setQuery("SELECT id,grad FROM login WHERE Email='$Email' AND Parola='$Parola' LIMIT 1");
//setQuery Is setting the Query
if($this->db->NumRows() > 0) {
//Checking if Number of Rows is greater than 0
if(session_id() == ''){
session_start();
}
$this->Email = $Email;
while($row = mysql_fetch_array($this->db->GetResource())){
//Fetching from the database the "Id" And "Grad"
$this->Id = $row[0];
$this->Grad = $row[1];
}
echo $this->Id . "<br />";
echo $this->Grad . "<br/>";
}
雖然是工作,我的計劃,我很不滿意的代碼,我想爲「ID信息「和」畢業「從這樣的」數據庫「。
$this->Id = $this->db->getInfo();
$this->Grad = $this->db->getInfo();
那麼這裏我想呼應 「ID」 和 「梯度」 我得到他的注意,當遇到問題
注意:數組字符串轉換在 C:\ XAMPP \ htdocs中\便便\類\ MVC \ userlogin.php第39行上陣列
代碼的getInfo():
//$this->Resource is the mysql_query of the setQuery
$this->Rows = array();
if ($this->Resource) {
while ($row = mysql_fetch_array($this->Resource)) {
$this->Rows[] = $row;
}
}
return $this->Rows;
我想提一提的是我是PHP和OOP的初學者。 代碼對所有功能使用http://tny.cz/4c5596fc
我意識到SQL注入是可能的,我將在稍後檢查PDO,因爲我可以獲得更多關於PHP的知識。 – camin10 2015-01-26 21:45:10