Skip to content

Instantly share code, notes, and snippets.

@phpdave
phpdave / db2_prepare_execute_select_query.php
Last active August 29, 2015 14:23
PHP DB2 connect prepare and execute a select statement with binded parameters
<?
$options = array('i5_lib' => 'MYLIB' ,'i5_libl' => 'MYLIB', 'i5_naming' => DB2_I5_NAMING_ON,'autocommit' => DB2_AUTOCOMMIT_OFF, 'cursor' => DB2_SCROLLABLE);
$db2Connection = db2_connect('DBNAME','USER', 'PASSWORD', $options);
if (!$db2Connection) { echo "false - Connection failed.";exit(); }
$sql_query="SELECT ALBUM.*
FROM ALBUM
WHERE ID = ?";
$sql_statement = db2_prepare($db2Connection, $sql_query);
if($sql_statement ===false) {echo 'Prepare Failed - Error: ' . db2_stmt_error() . "|".db2_stmt_errormsg() ;}
@phpdave
phpdave / index81.php
Last active August 29, 2015 14:24
Seperating Session files based on Port #
<?php
//C:/xampp/htdocs/81/
session_start();
$_SESSION['site']=81;
var_dump($_SESSION); //array (size=1) 'site' => int 81
@phpdave
phpdave / SerializingAPHPObjectInSession.php
Last active August 29, 2015 14:25
serializing php object in session
if(!isset($_SESSION['myobj']))
{
$myobj = new MyObj($parm);
$myobj->createSomething();
$_SESSION['myobj']=serialize($myobj);
}
$myobj = unserialize($_SESSION['myobj'])
--Create an Array type
CREATE TYPE phone_numbers_array_type AS VARCHAR(12) ARRAY[1000]
--Create a variable default_array of type phonenumberarray with a default array specified
CREATE OR REPLACE VARIABLE default_array phone_numbers_array_type DEFAULT ARRAY['416-413-9394', '416-413-7727', '416-413-6254'];
--Create a function using the array
CREATE OR REPLACE FUNCTION do_something_with_phone_numbers (
my_phone_numbers phone_numbers_array_type DEFAULT default_array)
RETURNS INTEGER
@phpdave
phpdave / Different file.php
Last active August 29, 2015 14:25
Netbeans PHP intellisense - type hinting to the IDE to get your class functions and vars
<?
/* @var $myclass MyClass */
$myclass = ServiceLocator::locate('MyClass');
$myclass->//::TODO:: press control space to invoke intellisense when the cursor is after the arrow to see the intellisense work!
@phpdave
phpdave / GetFormFieldsAndValuesIntoArrayThenJSON.html
Last active August 29, 2015 14:26
Takes the form data from HTML, adds some extra data, then encodes into JSON and request is sent to the server
<form id="myform">
<input id="CustomerName" name="CustomerName" type="text" />
<input id="Phone" name="Phone" type="text" />
...
</form>
<script type="text/javascript">
//Pull in all the data from the HTML form called myform
var postData = $("#myform").serializeObject();
CREATE TABLE LIB.MYJSON (
ID BIGINT,
DATA CLOB);
@phpdave
phpdave / UsingActiveRecord.php
Created August 13, 2015 13:29
Pattern Examples
<?
$post = new Post();
$post->title = 'My first blog post!!';
$post->author_id = 5;
$post->save();
# save runs SQL to insert the row into the db
@phpdave
phpdave / GetPrimaryKeyColumnsByTableIBMiDB2fori.sql
Last active August 29, 2015 14:27
Retreive the Primary key constraints columns by table name. #IBMi #DB2fori #SQL Thanks for Scott F. for the example code
WITH xx (CST_NAME, CST_COL_CNT, CST_SCHEMA, CST_TABLE) AS
(
SELECT CONSTRAINT_NAME, CONSTRAINT_KEYS, CONSTRAINT_SCHEMA, TABLE_NAME FROM QSYS2.SYSCST A
WHERE CONSTRAINT_TYPE = 'PRIMARY KEY' AND TABLE_NAME='MYTABLE'
)
SELECT CONSTRAINT_SCHEMA, TABLE_NAME, CONSTRAINT_NAME, COLUMN_NAME FROM QSYS2.SYSCSTCOL, xx where
xx.CST_SCHEMA = CONSTRAINT_SCHEMA AND
xx.CST_TABLE = TABLE_NAME AND
xx.CST_NAME = CONSTRAINT_NAME
@phpdave
phpdave / DefaultCABundle.php
Last active September 14, 2015 14:31
Pseudo code for detecting php version, operating system and a default location for CA bundle.
<?
$os = php_uname("s");
$phpversion = floatval(substr(phpversion (),0,3));
if($phpversion<5.6)
{
if($os=="OS400")
{
$defaultcafile = "/QOpenSys/QIBM/ProdData/SC1/OpenSSL/openssl-0.9.7d/cert.pem";
}
else if ($os=="Linux")