簡體   English   中英

如何跨類中的方法傳遞構造函數GET參數? 的PHP

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM