I'm using something like this for a query builder:
$queryHandler = new QueryHandler($connection);
$queryHandler->insert("someDataHere")
->into("someTable")
->when("sleep", 1000);
I want it to execute the query when the last method has been called on that statement, which in this case is the when function.
/**
* User: Bas
* Date: 8-12-2014
* Time: 20:11
*/
class QueryFunctions
{
.....
/**
* @param int|float|string| $data The data which is getting inserted
*
* @return $this
*/
public function insert($data) {
....
return $this;
}
public function into($table, $execute) {
....
return $this;
}
public function when($condition, $functionArgument) {
switch($condition) {
case "wait":
.....
break;
}
return $this;
}
/**
* To prevent instantiation
*/
private function __construct() {
}
}
How can i do this?
A common way is to invert the order of functions. Write:
$queryHandler->into("someTable")
->when("sleep", 1000)
->insert("someDataHere")
;
The insert() will trigger the query. I guess there is no other way in PHP except complex methods like workers or crontabs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With