Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/p2d0/prestashopsimpledbtables
https://github.com/p2d0/prestashopsimpledbtables
prestashop
Last synced: 22 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/p2d0/prestashopsimpledbtables
- Owner: p2d0
- License: gpl-3.0
- Created: 2018-09-27T09:24:42.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2021-10-28T14:55:08.000Z (about 3 years ago)
- Last Synced: 2024-11-13T11:43:17.199Z (about 2 months ago)
- Topics: prestashop
- Language: PHP
- Size: 33.2 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.html
- License: LICENSE
Awesome Lists containing this project
README
README.html
Prestashop Db tables
Installation
composer require cerki/simple_prestashop_persistence
Example usage
``` php
function getTableColumns(){
return [
"id" => "INTEGER NOT NULL PRIMARYKEY",
"myfield1" => "VARCHAR(255)",
"myfield2" => "INTEGER NOT NULL"
];
}
}
function myfunction(){
$mytable = new MyExampleTable(); // NOTE you should have prestashop Db class loaded
// so either do it in module/controller or import config.inc.php
$mytable->saveExistingColumns([
"myfield1" => "somedata1"
"myfield2" => 2
]);
$mytable->getBy(["myfield1" => "somedata1"]
// ["myfield2" => "ASC"] second argument - sorting
); // should return [["id" => 1,"myfield1" => "somedata1","myfield2"=>"somedata2"]]
}
```Updating columns
You can update existing columns by calling
php
$mytable->updateTableWithColumns([
"myfield3" => "BOOL" // add a new field
"myfield1" => "VARCHAR(1024) NOT NULL" // update existing field
]);Method list
php
function updateTableWithColumns($columns);
function dropTable();
function deleteBy($data); // Similar to getBy
function getBy($data,$order=NULL);
function saveExistingColumns($assoc_array); // NOTE saves a new instance if primary key is not included or doesn't exists, otherwise updates entry
function save($item) // normal insert throws error if primary key exists
function getAll();
function getColumnNames();Technicalities
- It Checks if table exists and creates a new one if it doesn't on each
new
call - It creates table with utf8 utf8unicodeci collation