$ This-> pdo-> exec ($ SQL );

Source: Internet
Author: User
{Code...} shows a source code written in this way. (I omitted a part) Why is it $ this-& amp; gt; pdo-& amp; gt; exec ($ SQL); instead of $ this-& amp; gt; exec ($ SQL); what is the role of this PDO?
class test{      protected $pdo;    function delete($sql){        $this->exec($sql);    }    function exec($sql){        echo $this->pdo->exec($sql);    }}$a=new test;$a->delete('ver');

The source code is written in this way. (I omitted some)

Why is it $ this-> pdo-> exec ($ SQL); instead of $ this-> exec ($ SQL );
What is the role of this PDO?

Reply content:
class test{      protected $pdo;    function delete($sql){        $this->exec($sql);    }    function exec($sql){        echo $this->pdo->exec($sql);    }}$a=new test;$a->delete('ver');

The source code is written in this way. (I omitted some)

Why is it $ this-> pdo-> exec ($ SQL); instead of $ this-> exec ($ SQL );
What is the role of this PDO?

Protected $ pdo; indicates the connection to Data. This variable is required when you need to execute SQL commands.

Estimated _ construct contains $ this-> pdo = new PDO (); and so on.
$ This-> pdo actually points to the PDO class.
$ This is only the current class
The error message above indicates that your $ SQL parameter is not passed.

Because you have not initialized pdo

public function __construct($pdo){    $this->pdo = $pdo;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.