如何跨类中的方法传递构造函数GET参数? PHP

时间:2011-10-25 17:36:56

标签: php oop class function methods

我基本上是尝试将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());
}       

3 个答案:

答案 0 :(得分:0)

您可以owner成为Updates的成员,并将其存储在this->owner

答案 1 :(得分:0)

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());
  }
}

答案 2 :(得分:0)

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());

    }   

*抱歉不得不编辑几次,复制和粘贴不正确,然后我想让它更清晰。