Created
December 17, 2015 18:00
-
-
Save jordiwes/ffb073f7f16df47b9282 to your computer and use it in GitHub Desktop.
bootstrap zend\db into a procedural script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* bootstrap.php | |
* Bootstraps an application. | |
* | |
* Zend Framework (http://framework.zend.com/) | |
* | |
* @link http://github.com/zendframework/ZendSkeletonApplication for the canonical source repository | |
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) | |
* @license http://framework.zend.com/license/new-bsd New BSD License | |
*/ | |
$zf2Path = false; | |
if (getenv('ZF2_PATH')) { // Support for ZF2_PATH environment variable or git submodule | |
$zf2Path = getenv('ZF2_PATH'); | |
} elseif (get_cfg_var('zf2_path')) { // Support for zf2_path directive value | |
$zf2Path = get_cfg_var('zf2_path'); | |
} | |
if ($zf2Path) { | |
if (isset($loader)) { | |
$loader->add('Zend', $zf2Path); | |
} else { | |
include $zf2Path . '/Zend/Loader/AutoloaderFactory.php'; | |
Zend\Loader\AutoloaderFactory::factory(array( | |
'Zend\Loader\StandardAutoloader' => array( | |
'autoregister_zf' => true | |
) | |
)); | |
} | |
} | |
if (!class_exists('Zend\Loader\AutoloaderFactory')) { | |
throw new RuntimeException('Unable to load ZF2. Define a ZF2_PATH environment variable.'); | |
} | |
//connect to the database | |
//$config = new Zend_Config_Ini(APPPATH . 'app.ini'); | |
$options = array("i5_naming" => DB2_I5_NAMING_ON, "i5_libl" => 'LIB1 LIB2'); | |
$db = new \Zend\Db\Adapter\Adapter(array( | |
'driver' => | |
'IbmDb2', | |
'platform' => 'IbmDb2', | |
'platform_options' => array('quote_identifiers' => false), | |
'database' => '*LOCAL', | |
'username' => 'PROFILE', | |
'password' => 'PASSWORD', | |
'driver_options' => $options | |
)); | |
?> | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* PHP includes | |
*/ | |
require('include/bootstrap.php'); | |
use Zend\Db\Sql\TableIdentifier; | |
use Zend\Db\TableGateway\TableGateway; | |
use Zend\Db\Sql\Select; | |
use Zend\Db\Sql\Sql; | |
use Zend\Db\Adapter\Adapter; | |
// Fetch the row for page | |
$dbobj = new Sql($db); | |
$dspSelect = $dbobj->select() | |
->from("APPRPATH", array("PATHID", "DOCDESC", "LOCDESC", "DEPTDESC", "DIVDESC", "CATDESC", "SUBCATDESC", "TYPEDESC", "PATHNCHAIN", "PATHNORIG")) | |
->join("TYPE", "TYPEID = PATHTYPE", array("TYPEDESC"), 'left') | |
->join("DOCTYPE", "DOCTYPEID = PATHDOC", array("DOCDESC"), 'left') | |
->join("LOCATION", "LOCID = PATHLOC", array("LOCDESC"), 'left') | |
->join("DEPARTMENT", "DEPTID = PATHDEPT", array("DEPTDESC"), 'left') | |
->join("DIVISION", "DIVID = PATHDIV", array("DIVDESC"), 'left') | |
->join("CATEGORY", "CATID = PATHCAT", array("CATDESC"), 'left') | |
->join("SUBCAT", "SUBCATID = PATHSUBCAT", array("SUBCATDESC"), 'left') | |
->where(array("PATHID" => $PATHID)); | |
//fetch the data | |
$statement = $dbobj->prepareStatementForSqlObject($dspSelect); | |
$rowset = $statement->execute(); | |
$row = $rowset->current(); | |
//insert row | |
$data['ALAPPROVAL'] = $requestID; | |
$data['ALSEQ'] = $seq; | |
$data['ALTIMEST'] = strtotime("now"); | |
$data['ALAPPRID'] = $userID; | |
$data['ALACTION'] = $action; | |
$insTable = new TableGateway("ACTIVTYLOG", $db); | |
$insTable->insert($data); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment