derilkillms/pdo-orm

使用pdo驱动器的orm连接

1.04 2023-03-21 08:48 UTC

This package is auto-updated.

Last update: 2024-09-21 12:06:58 UTC


README

安装

composer require derilkillms/pdo-orm

信息

关于ORM : (维基百科) 计算机科学中的对象关系映射(ORM,O/RM,以及O/R映射工具)是一种编程技术,用于在关系数据库和面向对象的编程语言的堆栈之间转换数据。这实际上创建了一个虚拟的对象数据库,可以在编程语言中使用。

....

本仓库基于:PHP

unset($CFG);
global $CFG;
$CFG = new stdClass();

$CFG->dbdriver  = 'pdo';
$CFG->dbtype    = 'mysql'; //mysql or pgsql
$CFG->dbhost    = 'localhost';
$CFG->dbname    = 'YOUR_DB_NAME';
$CFG->dbuser    = 'root';
$CFG->dbpass    = '';
$CFG->prefix    = 'd_';

require_once(__DIR__ .'/vendor/autoload.php'); // add derilkillms/pdo-orm/Database.php if not autoloaded

use Derilkillms\PdoOrm\Database;

$DB = new Database();

使用SQL查询

$users = $DB->get_records_sql("SELECT * FROM {users} where city=?",array('ciamis')); //for get rows data 

$user = $DB->get_record_sql("SELECT * FROM {user} where id=?",array(1)); // for get row data / one data 

$user = $DB->execute("DELETE FROM {user} WHERE id=?",array(1)); // for execute query like insert update delete

DML简单查询

//intialize key and value with object
$data = new stdClass();
$data->name = 'test';
$data->value = 'test';
//insert record
$insert =  $DB->insert_record('table', $data);


$data = new stdClass();
$data->id = 1; //id params is important for update
$data->name = 'tests';
$data->value = 'tests';
//update record
$update =  $DB->update_record('table', $data);
//delete record
$delete = $DB->delete_record('table','id=?',array(7));