<?php
/** NotORM - simple reading data from the database
if (!interface_exists('JsonSerializable')) {
interface JsonSerializable {
function jsonSerialize();
}
}
include_once dirname(__FILE__) . "/NotORM/Structure.php";
include_once dirname(__FILE__) . "/NotORM/Cache.php";
include_once dirname(__FILE__) . "/NotORM/Literal.php";
include_once dirname(__FILE__) . "/NotORM/Result.php";
include_once dirname(__FILE__) . "/NotORM/MultiResult.php";
include_once dirname(__FILE__) . "/NotORM/Row.php";
// friend visibility emulation
abstract class NotORM_Abstract {
protected $connection, $driver, $structure, $cache;
protected $notORM, $table, $primary, $rows, $referenced = array();
protected $debug = false;
protected $debugTimer;
protected $freeze = false;
protected $rowClass = 'NotORM_Row';
protected $jsonAsArray = false;
protected $isKeepPrimaryKeyIndex = FALSE; //@dogstar 20151230
protected function access($key, $delete = false) {
}
}
/** Database representation
class NotORM extends NotORM_Abstract {
/** Create database representation
* @param PDO
* @param NotORM_Structure or null for new NotORM_Structure_Convention
* @param NotORM_Cache or null for no cache
*/
function __construct(PDO $connection, NotORM_Structure $structure = null, NotORM_Cache $cache = null) {
$this->connection = $connection;
$this->driver = $connection->getAttribute(PDO::ATTR_DRIVER_NAME);
if (!isset($structure)) {
$structure = new NotORM_Structure_Convention;
}
$this->structure = $structure;
$this->cache = $cache;
}
/** Get table data to use as $db->table[1]
* @param string
* @return NotORM_Result
*/
function __get($table) {
return new NotORM_Result($this->structure->getReferencingTable($table, ''), $this, true);
}
/** Set write-only properties
* @return null
*/
function __set($name, $value) {
if ($name == "debug" || $name == "debugTimer" || $name == "freeze" || $name == "rowClass" || $name == "jsonAsArray" || $name == 'isKeepPrimaryKeyIndex') {
$this->$name = $value;
}
if ($name == "transaction") {
switch (strtoupper($value)) {
case "BEGIN": return $this->connection->beginTransaction();
case "COMMIT": return $this->connection->commit();
case "ROLLBACK": return $this->connection->rollback();
}
}
}
/** Get table data
* @param string
* @param array (["condition"[, array("value")]]) passed to NotORM_Result::where()
* @return NotORM_Result
*/
function __call($table, array $where) {
$return = new NotORM_Result($this->structure->getReferencingTable($table, ''), $this);
if ($where) {
call_user_func_array(array($return, 'where'), $where);
}
return $return;
}
}
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。
根据提供的知识库资料,您询问的内容似乎与直接访问数据库(特别是通过NotORM库)相关,而知识库中的参考资料主要涉及如何使用Spark SQL访问不同的数据存储系统(如Lindorm、MySQL、Azure Blob Storage)的数据。NotORM是一个轻量级的PHP库,用于简化从数据库读取数据的过程,这与参考资料中讨论的技术路径不同。
尽管如此,我可以帮助概括NotORM库的基本使用方法和特性,基于您提供的代码片段:
NotORM简介: NotORM是一个为PHP设计的简单数据库抽象层,它允许以面向对象的方式轻松地从数据库读取数据,而无需复杂的ORM映射配置。它通过分析数据库表之间的外键关系来自动生成查询。
核心特性:
$notORM->transaction = 'BEGIN|COMMIT|ROLLBACK';
简化事务控制。基本使用示例:
// 初始化NotORM实例
$pdo = new PDO('mysql:host=your_host;dbname=your_db', 'username', 'password');
$db = new NotORM($pdo);
// 访问表数据
$users = $db->users; // 获取users表的所有数据
$activeUsers = $db->users->where("status", "active"); // 获取状态为active的用户
// 链式调用示例
$recentActiveUsers = $db->users
->where("last_login > ?", date("Y-m-d H:i:s", strtotime("-1 week")))
->order("last_login DESC")
->limit(10);
请注意,上述内容是基于您提供的NotORM类定义代码进行的解释,并未直接引用知识库中的Spark SQL相关内容,因为这些参考资料与您的问题不直接相关。如果您需要了解如何结合NotORM与云服务(如阿里云上的数据库服务)进行数据操作,请提供更具体的需求说明。