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 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(); }
/** * @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); } }
/** * 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(); }
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; }
/** * @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); }
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'; $crul = new Application\View\Helper\CanonicalUrl(); $limpiando = new Application\View\Helper\Canonical(); foreach ($platos as $plato) { $platourl = $crul($limpiando($plato->va_nombre), array('suffix' => $plato->in_id)); $restauranteurl = $crul($limpiando($plato->restaurante)); $sm->addUrl($baseUrl . '/plato/' . $restauranteurl . '/' . $platourl); } $sm->updateRobots(); $result = $sm->send(); print_r($result);
<?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);