public function testGet() { $settings = $this->getMock('ML\SQL\Settings'); $connection = $this->getMock('ML\SQL\Connection_PDO_Sqlite', array(), array($settings)); $strategy = $this->getMock('ML\SQL\Strategy_Sqlite', array(), array($connection)); $sql = new SQL($connection, $strategy); $strategy->expects($this->never())->method('limit'); $sql->get("SELECT * FROM cat WHERE id = ?", array(1)); $strategy = $this->getMock('ML\SQL\Strategy_Sqlite', array(), array($connection)); $sql = new SQL($connection, $strategy); $strategy->expects($this->once())->method('limit'); $sql->get("SELECT * FROM cat WHERE id = ?", array(1), 10, 20); }
<?php use ml\sql\SQL; include('../ml/ml.php'); $dsn = 'pgsql://*****:*****@localhost/postgres'; $sql = SQL::createByDSN($dsn); $sql->query("TRUNCATE TABLE cat"); /*$conn = $sql->getConnection(); $conn->query("INSERT INTO cat (name, colour) VALUES (?, ?)", array('Nennek', 'black')); var_dump($conn->lastInsertId('cat', 'id')); */ var_dump($sql->save('cat', array('name' => 'Nennek', 'colour' => 'black')));
<pre> <?php use ml\sql\SQL; date_default_timezone_set('Europe/Warsaw'); include('../ml/ml.php'); $dsn = 'pgsql://*****:*****@localhost/postgres'; error_reporting(E_ALL); ini_set('display_errors', true); $pdo = new \PDO("pgsql:host=localhost;port=5432;dbname=postgres", 'postgres', 'mlsni2'); $pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); $connection = new ml\sql\Connection_PDO_PostgreSQL(new ml\sql\Settings()); $connection->setHandle($pdo); $strategy = new ml\sql\Strategy_PostgreSQL($connection); $sql = new SQL($connection, $strategy); print_r($sql->get("SELECT * FROM cats WHERE id = ?", array(1)));
<pre> <?php use ml\sql\SQL; date_default_timezone_set('Europe/Warsaw'); include('../ml/ml.php'); $dsn = 'pgsql://*****:*****@localhost/postgres'; error_reporting(E_ALL); ini_set('display_errors', true); $pdo = new \PDO("pgsql:host=localhost;port=5432;dbname=postgres", 'postgres', 'mlsni2'); $pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); $connection = new ml\sql\Connection_PDO_PostgreSQL(new ml\sql\Settings()); $connection->setHandle($pdo); $strategy = new ml\sql\Strategy_PostgreSQL($connection); $debug = new ml\sql\Connection_Decorator_Debug($connection); $sql = new SQL($debug, $strategy); print_r($sql->get("SELECT * FROM cats WHERE id = ?", array(1))); print_r($sql->getConnection()->getDebug());