Answer the question
In order to leave comments, you need to log in
How to continue a chain of requests in php?
I'm learning MySQL at the moment and noticed that we can access "internal queries" like in this example:
$mysqli->query("CREATE TABLE test(id INT, label TEXT)");
class A
{
public function get()
{
$sql = "SELECT * FROM users WHERE id = 123";
return $sql;
}
}
class B extends A
{
public function add($sql)
{
return $sql .= " AND name = 'Alex'";
}
}
$a = new A();
$b = new B();
echo $b->get()->add();
Answer the question
In order to leave comments, you need to log in
<?php
class A
{
protected $sql = null;
public function setSQL()
{
$this->sql = "SELECT * FROM users WHERE id = 123";
return $this;
}
public function getSQL()
{
return $this->sql;
}
}
class B extends A
{
public function addSQL()
{
$this->sql .= " AND name = 'Alex'";
return $this;
}
}
$a = new A();
$b = new B();
echo $b->setSQL()->addSQL()->getSQL();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question