Class DataObject
@package ErwanG
Database structure :
-
each table must have a primary key named "id" with type varchar(20)
-
foreign key must be tableName_id
-
associative tables must be TableName1_TableName2 (where TableName1<TableName2 in alphabetic order)
Example:
Book : id, title, editor_id
Author : id, firstName, lastName, birthDate
Author_Book : id, author_id, book_id
Editor : id, name
More examples in examples.php;
DataObject constructor.
return object with id
$book = Book::get('ABC');
@param $id
@return mixed|null
must be call to set PDO connection
DataObject::setPDO(['dbname'=>'database','host'=>'127.0.0.1','username'=>'root','password'=>'123456']);
@param $params must contain keys dbname, hostn username, password
@return PDO
@param $query
@return \PDOStatement
execute query and return result as DataObject
must be use for SELECT queries only
@param $query
@param array $params
@return array
execute query and return result
@param $query
@param array $params
@return \PDOStatement
return name table
default value is class name
@return string
return table columns
@return mixed
return DataObject from where query
@param $where
@param array $params
@param null $order
@param null $limit
@return DataObject[]
return first DataObject from where query
@param $where
@param array $params
@param null $order
@return DataObject|null
return last DataObject from where query
@param $where
@param array $params
@param null $order
@return DataObject|null
return DataObject from associative array
Book:find(['type'=>'thriller");
@param $params
@param null $order
@param null $limit
@return array
return first DataObject from associative array
@param $params
@param $order
@param bool $create if true, create object if not find
@return DataObject|null
return last DataObject from associative array
@param $params
@param $order
@return DataObject|null
return all object
@param null $order
@param null $limit
@return array
@param $name
@return array
@throws \Exception
create a DataObject from associative array
$author = Author::create(['firstname'=>'Victor','lastname'=>'HUGO']);
@param $params
@return DataObject
Set string ORDER BY...
@param $order
@return string
Set string LIMIT...
@param $limit
@return string
return count from where query
@param null $where
@param $params
@return int
return true if object is in database
@return bool
return an uniq id
@return bool|string
return object with relation
$books = $victorHugo->hasMany(Book::class);
@param string $class
@return array
@throws \Exception
@return string
@return string
@param null $separator
@return mixed|string
@param $class
@param bool $namespace
@return string
Store object in database
@return $this
@throws \Exception
delete object in database
@return bool
return true if table exists
@return boolean
test column existence
@param string $column column name
@return boolean
drop table
@param bool $foreignKeyCheck
@return bool
truncate table
@example CLASS::truncate(false);
@param bool $foreignKeyCheck
@return bool
populate object with associative array
@param $params
@return $this
@param Object $object
@return bool
copy object without id param
@return DataObject
begin transaction if none has been started
commit transaction
roll back