Skip to content

Instantly share code, notes, and snippets.

@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 / EmailValueObjectExample.php
Last active August 26, 2015 15:08
Playing around with Value Objects
<?
class EmailValue
{
protected $value;
public function __construct($emailAddress)
{
//sanitize for DB (NULL bytes, HTML and PHP tags stripped)
$emailAddress = strip_tags($emailAddress);
//Supposedly does more than strip tags
$emailAddress = xss_clean($emailAddress);
@phpdave
phpdave / HandleFileLock.php
Last active August 28, 2015 02:33
Handling the DB2 record lock exception in PHP when updating a record that has a lock.
<?
try
{
$user="BOB";
$id="2";
$db=new PDO("ReplceW/ConnectionString");
$stmt=$db->prepare("UPDATE `users` SET user=:user WHERE ID =:ID");
$stmt->bindParam(":user",$user);
$stmt->bindParam(":id",$id);
$stmt->execute();
@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")
@phpdave
phpdave / PHP and RPG comparison.md
Last active September 15, 2015 20:40
Notes: PHP and RPG comparison

###Invoke Program

PHP:

1.create myscript.php source file

2./usr/local/zendsvr/bin/php-cli myscript.php

RPG:

<tr>
<td>storeEval</td>
<td>new Array(&quot;&quot;,&quot;qa.&quot;,&quot;dev.&quot;);</td>
<td>application_environment_array</td>
</tr>
<tr>
<td>getEval</td>
<td>index=0;</td>
<td></td>
</tr>
{
"require": {
"facebook/webdriver": "~1.0"
}
}