public function testDbTableAbstractFactory__invokeIfConfigExist()
 {
     $createStatementStr = 'CREATE TEMPORARY TABLE IF NOT EXISTS test_res_tablle (id INT)';
     $createStatement = $this->adapter->query($createStatementStr);
     $createStatement->execute();
     $container = (include 'config/container.php');
     $requestedName = 'testDbTable';
     $result = $this->object->__invoke($container, $requestedName);
     $this->assertSame('zaboy\\rest\\DataStore\\DbTable', get_class($result));
 }
 public function testBuild()
 {
     $criteria = $this->criteriaFactory->build('Task', ['T4webInfrastructureTest\\Assets\\Active' => true, 'date_more' => '2015-10-30', 'id.isNotNull' => true, 'dateCreate.between' => ['2015-10-30', '2015-10-31'], 'relations' => ['User' => ['status.in' => [2, 3, 4], 'name.like' => 'gor']], 'limit' => 5]);
     $this->assertInstanceOf('T4webDomainInterface\\Infrastructure\\CriteriaInterface', $criteria);
     $this->assertEquals('Task', $criteria->getEntityName());
     /** @var \Zend\Db\Sql\Select $select */
     $select = $criteria->getQuery();
     $dbAdapter = new \Zend\Db\Adapter\Adapter(['driver' => 'Pdo', 'dsn' => 'mysql:dbname=board;host=localhost', 'driver_options' => [\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\''], 'username' => 'board', 'password' => '111']);
     $this->assertEquals("SELECT `tasks`.*" . " FROM `tasks`" . " INNER JOIN `users` ON `tasks`.`user_id` = `users`.`id`" . " WHERE `tasks`.`status` = '2'" . " AND `tasks`.`date_create` > '2015-10-30'" . " AND `tasks`.`id` IS NOT NULL" . " AND `tasks`.`date_create` BETWEEN '2015-10-30' AND '2015-10-31'" . " AND `users`.`status` IN ('2', '3', '4')" . " AND `users`.`name` LIKE 'gor'" . " LIMIT '5'", $select->getSqlString($dbAdapter->getPlatform()));
 }
 public function testRestRqlFactoryAbstractFactory__canCreateIfDataStorInConfigExist()
 {
     $tableName = 'table_for_db_data_store';
     $createStatementStr = "CREATE TABLE IF NOT EXISTS {$tableName} (id INT)";
     $createStatement = $this->adapter->query($createStatementStr);
     $createStatement->execute();
     $result = $this->object->__invoke($this->container, 'test_DataStoreDbTableWithNameAsResourceName');
     $this->assertSame(true, $result instanceof \Zend\Stratigility\MiddlewareInterface);
     $deleteStatementStr = "DROP TABLE IF EXISTS " . $tableName;
     $deleteStatement = $this->adapter->query($deleteStatementStr);
     $deleteStatement->execute();
 }
 public function testRestRqlFactoryAbstractFactory__canCreateIfTableExist()
 {
     $tableName = 'table_with_name_same_as_resource_name';
     $createStatementStr = "CREATE TABLE IF NOT EXISTS {$tableName} (id INT)";
     $createStatement = $this->adapter->query($createStatementStr);
     $createStatement->execute();
     $result = $this->object->__invoke($this->container, $tableName);
     $this->assertSame(true, $result instanceof \Zend\Stratigility\MiddlewareInterface);
     $deleteStatementStr = "DROP TABLE IF EXISTS " . $tableName;
     $deleteStatement = $this->adapter->query($deleteStatementStr);
     $deleteStatement->execute();
 }
 public function testTableGatewayAbstractFactory__invokeIfTableAbsent()
 {
     $createStatementStr = 'CREATE TABLE IF NOT EXISTS tbl_name_which_exist (id INT)';
     $createStatement = $this->adapter->query($createStatementStr);
     $createStatement->execute();
     $requestedName = 'tbl_name_which_exist';
     $result = $this->object->__invoke($this->container, $requestedName);
     $this->assertSame('Zend\\Db\\TableGateway\\TableGateway', get_class($result));
     $createStatementStr = 'DROP TABLE IF EXISTS tbl_name_which_exist';
     $createStatement = $this->adapter->query($createStatementStr);
     $createStatement->execute();
 }
Exemple #6
0
 public function index04Action()
 {
     $adapter = new \Zend\Db\Adapter\Adapter(array("driver" => "Pdo_Mysql", "database" => "books", "username" => "root", "password" => "", "hostname" => "localhost", "charset" => "utf8"));
     $sql = "SELECT * FROM `products` WHERE `id` = :id";
     $statement = $adapter->query($sql);
     //Zend\Db\Adapter\Driver\Pdo\Statement Object
     $result = $statement->execute(array("id" => "3"));
     echo "<pre style='font-weight:bold'>";
     print_r($result->current());
     echo "</pre>";
     // foreach ($result as $row) {
     // 	echo "<pre style='font-weight:bold;color:red'>";
     // 	print_r($row);
     // 	echo "</pre>";
     // }
     return $this->response;
 }
/**
 * @param Zend\Db\Adapter\Adapter $adapter
 */
function refresh_data($adapter)
{
    $platform = $adapter->getPlatform();
    $platformName = $platform->getName();
    $vendorData = (include __DIR__ . '/../setup/vendor/' . str_replace(' ', '-', strtolower($platformName)) . '.php');
    try {
        foreach ($vendorData['data_down'] as $downSql) {
            $adapter->query($downSql, $adapter::QUERY_MODE_EXECUTE);
        }
        foreach ($vendorData['data_up'] as $tableName => $tableData) {
            if ($tableData == null) {
                continue;
            }
            if (is_int($tableName) && is_string($tableData)) {
                $adapter->query($tableData, $adapter::QUERY_MODE_EXECUTE);
                continue;
            }
            foreach ($tableData as $rowName => $rowData) {
                $keys = array_keys($rowData);
                $values = array_values($rowData);
                array_walk($keys, function (&$key) use($platform) {
                    $key = $platform->quoteIdentifier($key);
                });
                array_walk($values, function (&$value) use($platform) {
                    switch (gettype($value)) {
                        case 'NULL':
                            $value = 'NULL';
                            break;
                        case 'string':
                            $value = $platform->quoteValue($value);
                            break;
                    }
                });
                $insertSql = 'INSERT INTO ' . $platform->quoteIdentifier($tableName) . ' (' . implode(', ', $keys) . ') ' . ' VALUES (' . implode(', ', $values) . ')';
                $adapter->query($insertSql, $adapter::QUERY_MODE_EXECUTE);
            }
        }
    } catch (\Exception $e) {
        echo $e->getMessage();
        var_dump($e);
        exit(1);
    }
}
Exemple #8
0
 /**
  * This method init $this->object
  */
 protected function _prepareTable($data)
 {
     $quoteTableName = $this->adapter->platform->quoteIdentifier($this->dbTableName);
     $deleteStatementStr = "DROP TABLE IF EXISTS " . $quoteTableName;
     $deleteStatement = $this->adapter->query($deleteStatementStr);
     $deleteStatement->execute();
     $createStr = "CREATE TABLE  " . $quoteTableName;
     $filds = $this->_getDbTableFilds($data);
     $createStatementStr = $createStr . '(' . $filds . ') ENGINE = InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci;';
     $createStatement = $this->adapter->query($createStatementStr);
     $createStatement->execute();
 }
Exemple #9
0
 /**
  * @group performance
  */
 public function testPerformance()
 {
     $zendAdapter = new \Zend\Db\Adapter\Adapter($this->connectData);
     $sql = "SELECT * FROM PRODUCT LIMIT 1000";
     $start = microtime(true);
     for ($i = 0; $i < 10; $i++) {
         $this->getDriver()->fetchAll($sql);
     }
     $modelTime = microtime(true) - $start;
     $start = microtime(true);
     for ($i = 0; $i < 10; $i++) {
         /** @var $statement \Zend\Db\Adapter\Driver\StatementInterface */
         $statement = $zendAdapter->query($sql);
         /* @var $results \Zend\Db\ResultSet\ResultSet */
         $result = $statement->execute();
         $rows = array();
         while ($row = $result->next()) {
             $rows[] = $row;
         }
     }
     $zendTime = microtime(true) - $start;
     echo "ZendTime: " . $zendTime . ' > ModelTime: ' . $modelTime . ' = ' . ($zendTime - $modelTime) . ' / ' . round($zendTime / $modelTime * 100) . '%';
     $this->assertLessThan($zendTime, $modelTime);
 }
<?php

require_once './autoloader.php';
$adapter = new Zend\Db\Adapter\Adapter(array('driver' => 'pdo', 'dsn' => 'mysql:dbname=db;hostname=localhost', 'username' => 'root', 'password' => 'password', 'driver_options' => array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\'')));
$adapter->getDriver()->getConnection()->beginTransaction();
Exemple #11
0
            file_put_contents($this->_basePath . $this->robotsFileName, $robotsFileContent);
        } else {
            $sampleRobotsFile = $sampleRobotsFile . "\n\nSitemap: " . $sitemapFullURL;
            file_put_contents($this->_basePath . $this->robotsFileName, $sampleRobotsFile);
        }
    }
}
//end class SiteMap
defined('APPLICATION_PATH') || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/..'));
set_include_path(implode(PATH_SEPARATOR, array(realpath(APPLICATION_PATH . '/vendor/zendframework/zendframework/library'), get_include_path())));
require_once 'Zend/Loader/StandardAutoloader.php';
$config = (include APPLICATION_PATH . '/config/autoload/global.php');
$autoLoader = new Zend\Loader\StandardAutoloader(array('prefixes' => array('MyVendor' => '/vendor/zendframework/zendframework/library/Zend'), 'fallback_autoloader' => true));
// register our StandardAutoloader with the SPL autoloader
$autoLoader->register();
$adapter = new \Zend\Db\Adapter\Adapter($config['db']);
$baseUrl = $config['host']['base'];
$avisoSitemapCount = 1;
$sm = new SiteMap($baseUrl, APPLICATION_PATH . '/public/');
$sm->sitemapIndexFileName = 'sitemap_index.xml';
$sm->sitemapFileName = 'platos' . str_pad($avisoSitemapCount, 2, '0', STR_PAD_LEFT) . '_sitemap.xml';
$sm->init();
$platos = $adapter->query('SELECT ta_plato.in_id,ta_plato.va_nombre,tr.va_nombre AS restaurante 
                FROM ta_plato
                LEFT JOIN `ta_plato_has_ta_local` AS `pl` ON `pl`.`ta_plato_in_id` = `ta_plato`.`in_id` 
                LEFT JOIN `ta_local` AS `tl` ON `tl`.`in_id` = `pl`.`ta_local_in_id`
                LEFT JOIN `ta_restaurante` AS `tr` ON `tr`.`in_id` = `tl`.`ta_restaurante_in_id`
                WHERE   ta_plato.en_estado=1  AND tr.en_estado=1
                GROUP BY in_id', $adapter::QUERY_MODE_EXECUTE);
include APPLICATION_PATH . '/module/Application/src/Application/View/Helper/CanonicalUrl.php';
include APPLICATION_PATH . '/module/Application/src/Application/View/Helper/Canonical.php';
Exemple #12
0
 /**
  * Construct ZendDb adapter.
  * @param  array  $dbConfig
  * @return \Zend\Db\Adapter
  */
 private static function zenddb()
 {
     self::requireConstants(array('DIRECTUS_ENV', 'DB_HOST', 'DB_NAME', 'DB_USER', 'DB_PASSWORD'), __FUNCTION__);
     $dbConfig = array('driver' => 'Pdo_Mysql', 'host' => DB_HOST, 'database' => DB_NAME, 'username' => DB_USER, 'password' => DB_PASSWORD, 'charset' => 'utf8', \PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true, \PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8");
     try {
         $db = new \Zend\Db\Adapter\Adapter($dbConfig);
         $db->getDriver()->getConnection()->connect();
     } catch (\Exception $e) {
         echo 'Database connection failed.';
         exit;
     }
     return $db;
     //        $dbConfig = array(
     //            'driver'    => 'Pdo_Mysql',
     //            'host'      => DB_HOST,
     //            'database'  => DB_NAME,
     //            'username'  => DB_USER,
     //            'password'  => DB_PASSWORD,
     //            'charset'   => 'utf8',
     ////            'options' => array(
     ////                \PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true
     ////            ),
     ////            'driver_options' => array(
     ////                \PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8; SET CHARACTER SET utf8;",
     //////                \PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true
     ////            )
     //        );
     //        $db = new \Zend\Db\Adapter\Adapter($dbConfig);
     //        $connection = $db->getDriver()->getConnection();
     //        try { $connection->connect(); }
     //        catch(\PDOException $e) {
     //            echo "Database connection failed.<br />";
     //            self::get('log')->fatal(print_r($e, true));
     //            if('production' !== DIRECTUS_ENV) {
     //                die(var_dump($e));
     //            }
     //            die;
     //        }
     //        $dbh = $connection->getResource();
     //        $dbh->exec("SET CHARACTER SET utf8");
     //        $dbh->query("SET NAMES utf8");
     ////        $pdo = $db->getDriver()->getConnection()->getResource();
     ////        $pdo->setAttribute(\PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
     //        return $db;
 }
Exemple #13
0
<?php

/**
 * Created by PhpStorm.
 * User: Glenn
 * Date: 2016-04-21
 * Time: 1:50 PM
 */
use Zend\Db\Sql\Ddl\CreateTable;
use Zend\Db\Sql\Ddl\Column;
use Zend\Db\Sql\Ddl\Constraint;
use Zend\Db\Sql\Ddl\DropTable;
require "./vendor/autoload.php";
$container = array();
include "./config/db.env.php";
$adapter = new \Zend\Db\Adapter\Adapter($container['settings']['db']);
$adapter->query("DROP TABLE IF EXISTS `users`", $adapter::QUERY_MODE_EXECUTE);
$table = new CreateTable('users');
$idColumn = new Column\Integer('id', false, NULL, array('autoincrement' => true));
$table->addColumn($idColumn);
$table->addColumn(new Column\Varchar('name', 255));
$table->addColumn(new Column\Varchar('username', 255));
$table->addColumn(new Column\Varchar('password', 255));
$table->addColumn(new Column\Varchar('email', 255));
$table->addConstraint(new Constraint\PrimaryKey('id'));
$adapter->query($table->getSqlString(new Zend\Db\Adapter\Platform\Mysql()), $adapter::QUERY_MODE_EXECUTE);
$adapter->query("ALTER TABLE `users` MODIFY COLUMN id INT auto_increment", $adapter::QUERY_MODE_EXECUTE);
Exemple #14
0
            }
        }
        closedir($handle);
    }
}
session_save_path($sessionDir);
require __DIR__ . '/../config/config.php';
require __DIR__ . '/../lib/ZendFramework-2.4.8/library/Zend/Loader/StandardAutoloader.php';
//require 'vendor/autoload.php';
$loader = new Zend\Loader\StandardAutoloader(array('autoregister_zf' => true, 'fallback_autoloader' => true));
$loader->register();
if (!isset($configArray) || !is_array($configArray)) {
    throw new Exception('Config file is wrong', 1512250909);
}
$config = new Zend\Config\Config($configArray);
$db = new Zend\Db\Adapter\Adapter($config->database->toArray());
$baktrace = debug_backtrace();
if (sizeof($baktrace) < 1) {
    throw new Exception('No backtrace available to create base path', 0710141057);
}
$db->baseDir = dirname($baktrace[0]['file']) . DIRECTORY_SEPARATOR;
$db->baseDir = str_replace('/shell/', '/', $db->baseDir);
try {
    $db->cache = Zend\Cache\StorageFactory::factory($config->cache->toArray());
} catch (\Exception $e) {
    if (preg_match('/Cache directory \'(.*)\' not found or not a directory/', $e->getMessage(), $catches)) {
        mkdir($catches[1]);
        $db->cache = Zend\Cache\StorageFactory::factory($config->cache->toArray());
    } else {
        throw $e;
    }