cerki/simple_prestashop_persistence

此包最新版本(1.0.6.2)没有提供许可证信息。

PHP的简单表格

1.0.6.2 2021-10-28 14:52 UTC

This package is auto-updated.

Last update: 2024-09-28 21:24:22 UTC


README

安装

composer require cerki/simple_prestashop_persistence

示例用法

<?php
use SimpleTables\Db\PrestaTable;
class MyExampleTable extends PrestaTable{
  function getTableName(){
    return "mytablename";
  }

  function getTableColumns(){
    return [
    "id" => "INTEGER NOT NULL PRIMARY KEY",
    "myfield1" => "VARCHAR(255)",
    "myfield2" => "INTEGER NOT NULL"
    ];
  }
}
function my_function(){
 $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"]]
}

更新列

您可以通过调用以下方法来更新现有列:

$mytable->updateTableWithColumns([
                                "myfield3" => "BOOL" // add a new field
                                "myfield1" => "VARCHAR(1024) NOT NULL" // update existing field
                                ]); 

方法列表

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();

技术细节

  • 它在每次new调用时检查表是否存在,如果不存在则创建一个新表
  • 它创建具有utf8 utf8_unicode_ci校对的表