Folge dem Video um zu sehen, wie unsere Website als Web-App auf dem Startbildschirm installiert werden kann.
Anmerkung: Diese Funktion ist in einigen Browsern möglicherweise nicht verfügbar.
<?php
class QueryCreate{
protected $table;
protected $fields;
protected $primarykey;
protected $indexkey;
public function __construct($table){
$this->table = $table;
$this->fields = array();
$this->primarykey = array();
$this->indexkey = array();
}
public function __destruct(){
unset($this);
}
public function addField($name, $typ){
$this->fields[$name] = $typ;
}
public function deleteField($name){
if(isset($this->fields[$name])){
unset($this->fields[$name];
}
return true;
}
public function create(){
$var = array();
$query ="CREATE TABLE ".$this->table." (\n";
foreach($this->fields as $field => $typ){
$var[]=$field." ".$typ;
}
if($this->issetPrimaryKey()){
$var[]=$this->getPrimaryKey();
}
if($this->issetIndex()){
$var[]=$this->getIndexKey();
}
$query.=implode(",\n", $var)."\n);";
}
public function setPrimaryKey($key){
$this->primarykey = $key;
}
protected function issetPrimaryKey(){
if(count($this->primarykey) > 0){
return true;
}
return false;
}
protected function getPrimaryKey(){
$pkey = array();
$count = count($this->primarykey);
for($i=0; $i<$count; $i++){
if(array_key_exists($this->primarykey[$i], $this->fields)){
$pkey[] = "PRIMARY KEY".$this->primarykey[$i];
}
}
return implode(",\n", $pkey);
}
public function deletePrimaryKey($key){
if(isset($this->primarykey[$key])){
unset($this->primarykey[$key]);
}
return true;
}
public function setIndexKey($key){
$this->indexkey = $key;
}
protected function issetIndexKey(){
if(count($this->indexkey) > 0){
return true;
}
return false;
}
protected function getIndexKey(){
$ikey = array();
$count = count($this->indexkey[$i];
for($i=0; $i<$count; $i++){
$ikey[] = "INDEX ".$this->indexkey[$i]."_Index(".$this->indexkey[$i].")";
}
return implode(",\n", $ikey);
}
public function deleteIndex($key){
if(isset($this->indexkey[$key])){
unset($this->indexkey[$key]);
}
return true;
}
}
?>