[英]How do you pass constructor GET parameter across methods in a class? PHP
我基本上是想將GET值從構造函數傳遞給insert_update函數。 我刪除了很多后者的功能。 另外,如果值得一提,則此頁面為包含頁面。
class Updates {
function __construct(){
$owner = $this->get = array_map('mysql_real_escape_string', $_GET);
$owner=$owner["member_id"];
echo $owner;
}
//Insert Update
public function Insert_Update()
{
$query = mysql_query("INSERT INTO `field` (foo) VALUES (N'$owner')") or die(mysql_error());
}
您可以使owner
成為Updates
的成員,並將其存儲在this->owner
。
class Updates {
private $owner;
function __construct(){
$owner = $this->get = array_map('mysql_real_escape_string', $_GET);
$this->owner=$owner["member_id"];
echo $this->owner;
}
//Insert Update
public function Insert_Update()
{
$query = mysql_query("INSERT INTO `field` (foo) VALUES (N'".$this->owner."')") or die(mysql_error());
}
}
class Updates {
protected $owner;
function __construct($myGetVariable)
$this->owner = $myGetVariable;
}
//Insert Update
public function Insert_Update()
{
// you can access the variable by typing:
echo $this->owner;
$query = mysql_query("INSERT INTO `field` (foo) VALUES (N'".$this->owner."')") or die(mysql_error());
}
*抱歉,必須編輯幾次,然后復制和粘貼錯誤,然后我才想更清楚一點。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.