



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




server, $this->username, $this->password, $this->db); // Check connection if ($conn->connect_error) { die("Connection failed: ". $conn->connect_error); }else{ echo "Success"; } $sql = "$sqlstatement"; $result = mysqli_query($conn, $sql); $conn->close(); return $result; } } interface Eloquent { public function get(); public function create($arrayInput); public function Update($arrayInput, $id); public function Delete($id); public function List($value, $key); public function Where($field, $operation, $value) } class Model implements Eloquent { public $model = "", public $table = "", public $field = array(), public $primary_key = ""; public function get(){ $result = []; $sqlString = "select * from {$this->table} {$this->condition} limit 10"; $dbsql = ($this->sqlexecute($sqlString)); if ($dbsql->num_rows > 0 ) { while($row = $dbsql->fetch_assoc()) { array_push($result , $row); } }
$this->model = $result; if(count($this->with)> 0 ) { $this->reCallWith(); } return $this->model; } public function lists($value, $key){ $result = []; $sqlString = "select * from {$this->table} {$this->condition} "; $dbsql = ($this->sqlexecute($sqlString)); if ($dbsql->num_rows > 0 ) { while($row = $dbsql->fetch_assoc()) { $result[$row["{$key}"]] = $row["{$value}"]; } } return $result; } public function with($arrInput){ $this->with = $arrInput; } public function reCallWith() { foreach($this->with as $callFunc) { $this->$callFunc(); } } public function hasMany($modelF, $foreignKey, $primary_key) { foreach($this->model as $key => $model) { $result = []; $objModelF = new $modelF; $sqlString = "select * from {$objModelF->table } where $foreignKey = $model[$primary_key]"; $dbsql = ($this->sqlexecute($sqlString)); if ($dbsql->num_rows > 0 ) { while($row = $dbsql->fetch_assoc()) { array_push($result , $row); } } $model["relation"]["{$modelF}"] = $result; $this->model[$key]["relation"]["{$modelF}"] = $result; } return $this->model; } public function belongTo($modelF, $foreignKey, $primary_key) { foreach($this->model as $key => $model)
public function get(); public function create($arrayInput); public function Update($arrayInput, $id); public function Delete($id); public function List($value, $key); public function Where($field, $operation, $value) } $objStudent = new Student; $objStuent->id= 1 ; $objStuent->name ///////////////////////////////// 2.**************************** server, $this->username, $this->password, $this->db); // Check connection if ($conn->connect_error) { die("Connection failed: ". $conn->connect_error); }else{ echo "Success"; } $sql = "$sqlstatement"; $result = mysqli_query($conn, $sql); $conn->close(); return $result; } } interface Eloquent { public function get(); public function create($input); public function update($input,$primaryKey); public function delete($primaryKey); public function lists($value, $key); } class Model implements Eloquent { public $model = []; public $with = []; public $table = ""; public $field = []; public $primary_key = ""; public function get() { //
$result = []; $sqlString = "select * from {$this->table} {$this->condition} limit 10"; $dbsql = ($this->sqlexecute($sqlString)); if ($dbsql->num_rows > 0 ) { while($row = $dbsql->fetch_assoc()) { array_push($result , $row); } } $this->model = $result; if(count($this->with)> 0 ) { $this->reCallWith(); } return $this->model; } public function create($arrInput) { // $strField=""; $strValue=""; foreach($arrInput as $key => $value) { $strField .= $key. ','; $strValue .= "'{$value}'". ','; } $strField = rtrim($strField, ","); $strValue = rtrim($strValue, ","); $sqlString = "insert into {$this->table}({$strField}) values($strValue);"; return $this->sqlexecute($sqlString); } public function update($arrInput,$primaryKey) { // } public function delete($primaryKey) { // } public function lists($value, $key) { // Array : Key - > Value $result = []; $sqlString = "select * from {$this->table} {$this->condition} "; $dbsql = ($this->sqlexecute($sqlString)); if ($dbsql->num_rows > 0 ) { while($row = $dbsql->fetch_assoc()) { $result[$row["{$key}"]] = $row["{$value}"]; }