kroyxlab/datbazo

DatBazo(Datuma Bazo, Esperanto数据库) 是一个使用PDO的SQL查询构造器。

1.2.0 2019-04-14 17:23 UTC

This package is auto-updated.

Last update: 2024-09-16 08:06:02 UTC


README

DatBazo

DatBazo(Datuma Bazo, Esperanto数据库) 是一个使用PDO的SQL查询构造器。是一个小巧的库,可以帮助您快速创建数据库查询,使用PDO的“Prepare”和“Execute”方法来避免SQL注入。

目录

  1. 依赖
  2. 安装
  3. 入门
  4. 方法
  5. 作者
  6. 许可

依赖

此包需要PHP 7或更高版本。

安装

通过composer

composer require kroyxlab/datbazo

复制仓库

将直接仓库复制到您的项目中并引入类。

require_once 'proyect_directory/datbazo/src/DatBazo.php';
use kroyxlab\datbazo\DatBazo as DatBazo;

入门

修改位于文件夹 vendor/kroyxlab/datbazo/src/DBconfig.ini 的 KLPdo.ini 文件,并修改值以配置数据库连接。

[databazo]
db_driver = Mysql || sqlite3 || pgsql
db_host = Host_name
db_port = Port
db_name = Database_name
db_user = user
db_password = password
db_charset = UTF8

如果一切配置正确,您就可以开始使用这个库了。

require_once "vendor/autoload.php";
use kroyxlab\datbazo\DatBazo as DatBazo;

// instantiate the DatBazo class
$productos = new DatBazo;

// Create an SQL statement using the methods of the KLPdo class
$products->select(['products'=>'name, price'])
          ->where(['price'=>['>=', 12.5]])
          ->order('price')
          ->execute();

// Set the type of fetch you want.
$products->fetch('assoc');

// Use the Method -> render (); to output and format the result of the sql query
$products->render(function($product){

  return "<p>The name of the product is {$product['name']} and the price is {$product['price']}</p>";

});

// Or use a foreach loop using the fetch method

foreach($products->fecth('obj') as $product){
  echo "<p>The name of the product is $product->name and the price is $product->price</p>"
}

方法

DatBazo类的这些方法有助于创建将通过Pdo的prepareexecute方法执行的SQL语句,以避免SQL注入。

方法列表

作者

许可

本项目遵循MIT许可证 - 有关详细信息,请参阅MIT.md文件。