Add correct read support (filter without value, bad key assignement)
git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@1218 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
24
dblayer.php
24
dblayer.php
@@ -46,7 +46,9 @@ class dblayer extends PDO
|
|||||||
|
|
||||||
// TODO !!
|
// TODO !!
|
||||||
/** Create automatic creation of $fields from .schema of sqlite3/
|
/** Create automatic creation of $fields from .schema of sqlite3/
|
||||||
show create table `NomTable`; for MySQL*/
|
show create table `NomTable`; for MySQL
|
||||||
|
SQLite3 : PRAGMA TABLE_INFO('yourtable');
|
||||||
|
MYSQL : SHOW COLUMNS FROM yourtable;*/
|
||||||
|
|
||||||
/** Connection to the database engine
|
/** Connection to the database engine
|
||||||
See http://fr2.php.net/manual/en/pdo.construct.php for the $dsn format */
|
See http://fr2.php.net/manual/en/pdo.construct.php for the $dsn format */
|
||||||
@@ -100,24 +102,30 @@ class dblayer extends PDO
|
|||||||
return $this->db->lastInsertId();
|
return $this->db->lastInsertId();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Read all the table or only one line defined by the primary key */
|
/** Read all the table or only one line defined by the select key, the select
|
||||||
function read ($selectkey=null)
|
operator and the associated select value */
|
||||||
|
function read ($selectkey=null, $selectval=null, $selectop="=")
|
||||||
{
|
{
|
||||||
if ($this->db === null)
|
if ($this->db === null)
|
||||||
throw new Exception ("Database not connected");
|
throw new Exception ("Database not connected");
|
||||||
|
if ($selectop !== "=" && $selectop !== "like" && $selectop !== null)
|
||||||
|
throw new Exception ("Invalid selectop");
|
||||||
|
if ($selectkey !== null &&
|
||||||
|
! in_array ($selectkey, array_keys ($this->fields)))
|
||||||
|
throw new Exception ("Unknown key field provided");
|
||||||
$req = "SELECT ";
|
$req = "SELECT ";
|
||||||
$req .= implode (",", array_keys ($this->fields));
|
$req .= implode (",", array_keys ($this->fields));
|
||||||
$req .= " FROM `".$this->table."`";
|
$req .= " FROM `".$this->table."`";
|
||||||
if ($selectkey !== NULL)
|
if ($selectkey !== NULL && $selectval !== NULL)
|
||||||
$req .= " WHERE $this->primary=:primary";
|
$req .= " WHERE $selectkey $selectop :selectkey";
|
||||||
|
|
||||||
if ($this->debug) echo "DEBUG : $req\n";
|
if ($this->debug) echo "DEBUG : $req\n";
|
||||||
$st = $this->db->prepare ($req);
|
$st = $this->db->prepare ($req);
|
||||||
if ($selectkey !== NULL)
|
if ($selectkey !== NULL && $selectval !== NULL)
|
||||||
{
|
{
|
||||||
if ($this->debug) echo "DEBUG BIND : primary->".
|
if ($this->debug) echo "DEBUG BIND : selectkey->".
|
||||||
var_export ($selectkey, TRUE)."\n";
|
var_export ($selectkey, TRUE)."\n";
|
||||||
$st->bindValue (":primary", $selectkey);
|
$st->bindValue (":selectkey", $selectval);
|
||||||
}
|
}
|
||||||
$st->execute ();
|
$st->execute ();
|
||||||
$res = array ();
|
$res = array ();
|
||||||
|
|||||||
Reference in New Issue
Block a user