Added wtable in other file

This commit is contained in:
absurdo 2023-10-27 23:12:08 +02:00
parent e0b8e8e8e3
commit 731bdfcf82
3 changed files with 65 additions and 37 deletions

View file

@ -2,21 +2,6 @@
namespace PhangoApp\WPDO;
class WTable {
public $table;
public $fields;
public function __construct($table, $fields) {
$this->name=$table;
$this->fields=$fields;
}
}
class WPDO {
static public $host_db='';
@ -49,19 +34,21 @@ class WPDO {
echo 'Cannot connect to the mysqldb';
exit();
return false;
}
$this->conn=new \PDO(WPDO::$driver.':host='.WPDO::$host_db.';dbname='.WPDO::$db, WPDO::$login_db, WPDO::$pass_db);
return true;
}
public function query($query, $values) {
$this->sth=$this->conn->prepare($query);
$this->sth->execute([$values]);
//$this->sth->execute([$values]);
return $this->sth->execute($values);
@ -74,8 +61,6 @@ class WPDO {
$query='select '.$str_fields.' from '.$this->table->name.' '.$where_sql;
$this->sth=$this->conn->prepare($query);
$this->sth->execute($values);
return $this->sth->execute($values);
@ -128,7 +113,7 @@ class WPDO {
}
public function check_fields($fields) {
if($fields[0]!='*') {
$final_fields=[];
@ -142,19 +127,17 @@ class WPDO {
}
}
$str_fields=implode(', ', $final_fields);
}
else {
$str_fields='*';
$final_fields=['*'];
}
if(count($final_fields)==0) {
throw new Exception('No valid fields selected in '.$this->table->name);
throw new \Exception('No valid fields selected in '.$this->table->name.' Valid fields are '.implode(', ', $this->table->fields).' . Fields passed are: '.implode(', ', $fields));
}
@ -163,3 +146,4 @@ class WPDO {
}
}

19
src/WTable.php Normal file
View file

@ -0,0 +1,19 @@
<?php
namespace PhangoApp\WPDO;
class WTable {
public $table;
public $fields;
public function __construct($table, $fields) {
$this->name=$table;
$this->fields=$fields;
}
}