<?php
class DB {
var $query;
var $sql;
public function __construct() {
$this->sql = new mysqli("localhost", "root", "", "database");
}
public function update($tab) {
$this->query .= "UPDATE " . $tab;
}
public function set($set) {
$this->query .= " SET " . $set;
}
public function where($where) {
$this->query .= " WHERE " . $where;
}
public function execute() {
echo $this->query;
}
}
$db = new DB();
$db->update("user");
$db->set("nome='arturo'");
$db->where("id=25");
$db->execute();
?>
<?php
class DB {
var $query;
var $sql;
public function __construct() {
$this->$sql = new mysqli("localhost", "root", "", "database");
}
public function update($tab) {
$this->query .= "UPDATE " . $tab;
}
public function set($set) {
$this->query .= " SET " . $set;
}
public function where($where) {
$this->query .= " WHERE " . $where;
}
public function execute() {
echo $this->query;
}
}
$db = new DB();
$db->update("user");
$db->set("nome='arturo'");
$db->where("id=25");
$db->execute();
?>
Scusami forse sono stato io a nn farmi capire. Mi servirebbe questo metodo:
PHP:
$db = new DB();
/* Per fare questo come bisogna impostare la classe o bisogna creare piu classi ? */
$db->update( user )->set( nome=arturo )->where( ID=25 );
Forse ho trovato qualcosa solo che la query mi torna nulla. Forse sbaglio qualcosa !
PHP:
class DB {
var $query, $update, $set, $where;
function update($a){
$this->update = new Update($a);
return $this->update;
}
function exe(){
var_dump( $this->query );
}
}
class Update extends DB {
function __construct($a){
$this->query = 'UPDATE '.$a;
}
function set($a){
$this->set = new Set($a);
return $this->set;
}
}
class Set extends DB {
function __construct($a){
$this->query .= ' SET '.$a;
}
function where($a){
$this->where = new Where($a);
return $this->where;
}
}
class Where extends DB {
function __construct($a){
$this->query .= ' WHERE '.$a;
}
}
$db = new DB;
$db->update('user')->set('name="arturo"')->where('ID=25');
$db->exe();
class DB {
static $query;
static function update( $a ){
self::$query = 'UPDATE '.$a;
return new Update( $a );
}
static function exe(){
return self::$query;
}
}
class Update extends DB {
static function set( $a ){
self::$query .= ' SET '.$a;
return new Set( $a );
}
}
class Set extends DB {
static function where( $a ){
self::$query .= ' WHERE '.$a;
}
}
class Where extends DB {
}
echo '<pre>';
$db = new DB;
$db->update( 'user' )->set( 'name="Arturo"' )->where( 'ID="25"' );
print_r( $db::exe() );