Fastest way to connect to DB with existing .env
Posted: 10 Jul 2024, 14:34pm - Wednesday

 Several projects now I ended up to create a standalone script to do specific task. Loading doctrine would be using lots of resources. I always want to create a lite-weight script to do specific tasks but connecting to the DB is a bit tricky when you are in a framework (symfony + doctrine).

 
$connection = $_ENV['DATABASE_URL'];
list(
    $driver,,, $username, $password,
    $host, $port, $db_name, $extra1
) = preg_split('/(:|\/|@|\?|&)/', $connection);

$sql = new xSQL([
    'driver' => $driver,
    'port' => $port,
    'database' => $db_name,
    'host' => $host,
    'username' => $username,
    'password' => $password
], true);

 

This is how I do it.. Helps a lot doing this way.

enlarge
RoundCube WebMail plugin: 2-Factor Authentication (2FA)
Posted: 26 Oct 2021, 21:50pm - Tuesday

I was looking for a plugin to implement 2FA in my mail server. I found alexandregz/twofactor_gauthenticator but its quite outdated and quirky. Seems not maintained. So I forked it, the foundation is there and just need to improve it.

After few days of work, here's my improved 2FA for RoundCube webmail. Please feel free to use it and it works well with RoundCube v1.5.x

Git Repo: https://github.com/camilord/twofactor_gauthenticator

enlarge
Symfony 5.2 Command / Console connecting to DBAL
Posted: 8 Feb 2021, 6:51am - Monday

I have been searching how my Symfony Command/Console can connect to the database using DBAL. Somehow there's no working solution that its not either deprecated or the solution was lower version of what I am looking for.

So I made my own solution, takes a while but it works.

  1. I used the Symfony\Dotenv class to read the .env file and get DATABASE_URL value
  2. Then I created a class to parse the DATABASE_URL value to Driver/Connection class required array structure (see screenshot below, $db_options variable)
  3. then I instantiate Driver class and feed the parsed array and Driver to Connection (see sample code below)

Filename: DatabaseUrlEnvUtil

/**
 *  // mysql://root:secret@127.0.0.1:3306/dbname?serverVersion=5.7
 *
 * Class DatabaseUrlEnvUtil
 * @package App\Utils
 */
class DatabaseUrlEnvUtil
{
    /**
     * @param string $str
     * @return array
     */
    public static function convertToArray(string $str) {
        $breakers = [
            /*'driver' => [
                'delimeter' => '://',
                'position' => 0
            ],*/
            'user' => [
                'delimeter' => [':', '//'],
                'position' => [1, 1]
            ],
            'password' => [
                'delimeter' => [':', '@'],
                'position' => [2, 0]
            ],
            'host' => [
                'delimeter' => ['@', ':'],
                'position' => [1, 0]
            ],
            'dbname' => [
                'delimeter' => ['/', '?'],
                'position' => [3, 0]
            ],
            'port' => [
                'delimeter' => [':', '/'],
                'position' => [3, 0]
            ]
        ];

        $data = [];
        foreach($breakers as $key => $breaker) {
            $delimeter = isset($breaker['delimeter']) ? $breaker['delimeter'] : null;
            $position = isset($breaker['position']) ? $breaker['position'] : 0;

            if (is_null($delimeter)) {
                continue;
            }

            if (is_array($delimeter)) {
                $tmp_data = $str;
                foreach($delimeter as $i => $item) {
                    $tmp = explode($item, $tmp_data);
                    $tmp_data = $tmp[$position[$i]];
                }
                $data[$key] = $tmp_data;
            } else {
                $tmp = explode($delimeter, $str);
                $data[$key] = isset($tmp[$position]) ? $tmp[$position] : null;
            }
        }

        return $data;
    }
}

Console/Command Output:

That's it, problem solved.

enlarge
ASP.Net Core C#: Handling new lines in Razor view
Posted: 21 Mar 2020, 20:52pm - Saturday

I've been programming using PHP for a long time, and its funny I am struggling to do it on ASP.Net Core C#. In PHP, all you need to do is call the function "nl2br()" and that's it.

In this blog, I am reminding myself how to do it in ASP.Net Core C#. There are two ways how to resolve my issue:

Method 1 is adding an css line but this approach is not always applicable.
Method 2 is calling Razor Html.Raw() method. I believe this is a better approach. But be careful of XSS attack on this. Make sure you sanitize before saving to database.

I think that's it... Hope for the readers of this post looking for answers like me will help you as well.

enlarge
POLi Payment Gateway: Why you shouldn't use this option...
Posted: 11 Apr 2016, 1:59am - Monday
poli_1           The first time I saw POLi payments was in Qantas Airlines New Zealand. The moment I saw asking for my Bank Credentials, I click back button ripoli_3ght away. Why? Because POLi is asking your Access Code/Username and Password of your bank, your BANK CREDENTIALS! Imagine your hosts file has been altered by malware or any virus or your network has been hacked or exploited or your ISP has been hacked or whatever above your internet line has been altered pointing POLi payment gateway's DNS to different server, you will be giving your bank access to the hackers. And POLi is a direct access to your bank account (your entire assets in your bank) and initiate the transaction right away. Unlike credit cards, if your card has been expospoli_2ed, then the risk is JUST your card, not your whole account in the bank then you still have time to call the bank the close it right away. So my advise never use POLi payments. I'm not against the company or the people who created it but I am just against how the implementation or how it works.
enlarge
Selwyn District Council Consents
Posted: 18 Sep 2014, 1:24am - Thursday
Wohooo... It is really good hearing this news. TRIAD { sid, michael, camilo3rd } is behind this online tool. Online Building Consent System is powered by: Alpha 77 Limited (www.abcs.co.nz) Legacy of Adam Jones of QCIT Ltd (www.qcit.co.nz)
enlarge
Allow postfix  to send email with different sender from SMTP account... Error:
postfix/smtpd[27402]: NOQUEUE: reject: RCPT from unknown[125.123.123.100]: 553 5.7.1 <user@xxx.co.nz>: Sender address rejected: not owned by user user@xxx.co.nz; from=<xxx@xxx.co.nz> to=<xxx@gmail.com> proto=ESMTP helo=<localhost>
Edit postfix configuration:
[root@mail ~]# nano /etc/postfix/main.cf
Change from:
smtpd_sender_restrictions = permit_mynetworks, reject_sender_login_mismatch, permit_sasl_authenticated
To:
smtpd_sender_restrictions = permit_mynetworks, permit_sasl_authenticated
Then restart postfix...
[root@mail ~]# postfix stop
postfix/postfix-script: stopping the Postfix mail system
postfix/postfix-script: waiting for the Postfix mail system to terminate
[root@mail ~]# postfix start
postfix/postfix-script: starting the Postfix mail system
[root@mail ~]#
That's it.. You can now change your from or reply-to in your PHPMailer. :) Hope this helps...
enlarge
JPGRAPH I always stumble down with this error for couple of projects now.
JpGraph Error: 25128 The function imageantialias() is not available in your PHP installation. Use the GD version that comes with PHP and not the standalone version.
Two solutions as I know:
  1. install the required library
  2. or simply comment certain line
  For solution #1, simply cast yum install php-gd. For solution #2, as of version 3.5.0b1 -- comment line 110 (function SetAntiAliasing) at file gd_image.inc.php and that's it... problem solved. Another issue will be fonts:
JpGraph Error: 25049 Font file "/usr/share/fonts/truetype/arialbd.ttf" is not readable or does not exist.
Look for jpg-config.inc.php and add these lines:
define('CACHE_DIR','cache/');
define('TTF_DIR','includes/jpgraph/fonts/');
Note: Just place the right path where you setup your jpgraph folder Download required JpGraph Fonts: [download id="39"] And that should solve the problems... :) Samples:

progression_graph_1386128392 progression_graph_1386188039

enlarge
PHP + Firebird SQL Installation
Posted: 28 May 2013, 22:20pm - Tuesday
Download the following: (In my case, it's 64bit)
  1. PHP
  2. Apache
  3. Firebird (http://www.firebirdsql.org/en/firebird-2-5-2-upd1/)
After installation of PHP, edit the php.ini and uncomment:
  • php_interbase.dll
  • php_pdo_firebird.dll
At command prompt, cast php -v and you will have an error:
PHP Warning:  PHP Startup: Unable to load dynamic library 'C:\php\ext\php_interbase.dll' - The specified module could not be found.
 in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library 'C:\php\ext\php_pdo_firebird.dll' - The specified module could not be found.
 in Unknown on line 0
PHP 5.4.9 (cli) (built: Nov 21 2012 19:54:46)
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies
Install the Firebird... Try again casting a command php -v
C:\Workspace\localhost\vshbdata>php -v
PHP 5.4.9 (cli) (built: Nov 21 2012 19:54:46)
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies
Meaning, the firebird is successfully installed. Second test is create a php script:
<?php

foreach(PDO::getAvailableDrivers() as $driver) {
  echo $driver.'<br />';
}

?>
You should see firebird in the list...
enlarge
BeeCheckout Online Ordering System
Posted: 19 Jun 2024, 16:59pm - Wednesday

 When you own a restaurant or food shop, online presence is highly recommended to increase sales. Ordering online is a must too. Several online ordering providers are in the wild and daunting to choose from. Then, most of them are commission based platform!

Imagine a online ordering system that bill you on fixed price, not commission based, which more profitable on your side? Try BeeCheckout - https://www.beecheckout.com, take control of your sales and say good bye with commission based platform.

enlarge
Windows: Setting up Apache 2.4.48 and PHP 7.4.20
Posted: 13 Jul 2021, 23:43pm - Tuesday

Before going thru the steps below, you need to download the installers first at http://camilord.com/downloads/Apache2.4.48_PHP7.4.20.zip

Then, just extract the zip which will give you both apache (httpd-2.4.48-o111k-x64-vc15) and php (php-7.4.20-Win32-vc15-x64). They are also in a zip, extract it in "C:\" and rename it like below.

would look like:

C:\Apache24
C:\php

then in apache, go to httpd.conf and edit it.
Add the following lines:

# php 7.4.20 handler
AddHandler application/x-httpd-php .php
AddType application/x-httpd-php .php .html
LoadModule php7_module "c:/php/php7apache2_4.dll"
PHPIniDir "c:/php"

you can skip this step, you only do this when you have existing apache installation

httpd -k uninstall -n "Apache2.4"

then save it. go to Apache24\bin using CLI or powershell (as administrator) then run:

httpd.exe -k install -n "Apache2.4"

this will install as a service. then to start and stop

httpd -k start
httpd -k stop

or

net start "Apache2.4"
net stop "Apache2.4"

then for PHP, copy the php.ini-development as php.ini then adjust the necessary configuration
needed by your application. then since you're in dev mode, add this at the end of the php.ini:

[Xdebug]
zend_extension="C:/php/ext/php_xdebug-3.0.4-7.4-vc15-x86_64.dll"
xdebug.client_port="9003"
xdebug.mode=debug
;xdebug.mode=profile

you can find the file in this folder and make sure you copy that xdebug dll file to C:\php\ext\

then restart the apache…

and if you have changes in your php.ini on next edit, restart again your apache.

enlarge
GitLab: docker DNS issue and container already in use
Posted: 6 May 2020, 21:46pm - Wednesday

I decided to create another stage to test our API in GitLab CI runner using postman/newman. I made it work but there are issues from time to time like DNS issue and "container already in use" (see screenshot below). The common error that occurs most of the time is the DNS issue.

docker DNS issue

In my various experiments, I managed to resolve the `container already in use` issue by adding the container name with commit ID from gitlab.

docker container already in use issue
.gitlab-ci.yml

However, since I implemented the commit ID on the container, the DNS issue reduced from 8/10 fails to 2/10 fails. It still fail time to time, its not perfect but for now its tolerable. I hope there's a better solution.

success like.. wohooo!
enlarge
NZ Companies Register API
Posted: 25 Feb 2018, 3:50am - Sunday
In case you need it... https://github.com/camilord/nz-companies-register Very simple to use...
 
 
use camilord\NZCompaniesRegister\NZCompaniesRegister;
 
$obj = new NZCompaniesRegister();
$result = $obj->search('blue horn');
 
print_r($result);
 
Cheers!
enlarge
MySQL Constraints: Import
Posted: 10 Mar 2015, 2:09am - Tuesday
I stumbled down again of database constraints when importing SQL dump file.
ERROR 1217 (23000) at line 128: Cannot delete or update a parent row: a foreign key constraint fails
The solution is add the following line in the beginning of the SQL dump file:
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0
That should work.
enlarge
PHP Deployment Tool: Mage
Posted: 18 Aug 2014, 23:56pm - Monday
I've been using this php deployment tool called magallanes or mage php. It is pretty cool. For more details of this tool, visit http://magephp.com I did a fork because its not working well on windows. My Fork: https://github.com/camilord/Magallanes My fixes are issues on tarballing the the project and the rsync to the server. mage
enlarge
Symfony2: Install/Create Project
Posted: 30 Jan 2014, 4:10am - Thursday
C:\php>php composer.phar install
Warning: This development build of composer is over 30 days old. It is recommended to update it by running "composer.phar self-update" to get the latest version.
Composer could not find a composer.json file in C:\php
To initialize a project, please create a composer.json file as described in the http://getcomposer.org/ "Getting Started" section

C:\php>php composer.phar self-update
Updating to version 0238aaf5ac565a5b896caa79e9ca7e71d2312343.
    Downloading: 100%

C:\php>php composer.phar install
Composer could not find a composer.json file in C:\php
To initialize a project, please create a composer.json file as described in the http://getcomposer.org/ "Getting Started" section

C:\php>composer install
'composer' is not recognized as an internal or external command,
operable program or batch file.

C:\php>php composer install
Could not open input file: composer

C:\php>php composer.phar
   ______
  / ____/___  ____ ___  ____  ____  ________  _____
 / /   / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
                    /_/
Composer version 0238aaf5ac565a5b896caa79e9ca7e71d2312343 2014-01-29 09:12:19

Usage:
  [options] command [arguments]

Options:
  --help           -h Display this help message.
  --quiet          -q Do not output any message.
  --verbose        -v|vv|vvv Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
  --version        -V Display this application version.
  --ansi              Force ANSI output.
  --no-ansi           Disable ANSI output.
  --no-interaction -n Do not ask any interactive question.
  --profile           Display timing and memory usage information
  --working-dir    -d If specified, use the given directory as working directory.

Available commands:
  about            Short information about Composer
  archive          Create an archive of this composer package
  config           Set config options
  create-project   Create new project from a package into given directory.
  depends          Shows which packages depend on the given package
  diagnose         Diagnoses the system to identify common errors.
  dump-autoload    Dumps the autoloader
  dumpautoload     Dumps the autoloader
  global           Allows running commands in the global composer dir ($COMPOSER_HOME).
  help             Displays help for a command
  init             Creates a basic composer.json file in current directory.
  install          Installs the project dependencies from the composer.lock file if present, or falls back on the composer.json.
  licenses         Show information about licenses of dependencies
  list             Lists commands
  require          Adds required packages to your composer.json and installs them
  run-script       Run the scripts defined in composer.json.
  search           Search for packages
  self-update      Updates composer.phar to the latest version.
  selfupdate       Updates composer.phar to the latest version.
  show             Show information about packages
  status           Show a list of locally modified packages
  update           Updates your dependencies to the latest version according to composer.json, and updates the composer.lock file.
  validate         Validates a composer.json

C:\php>php composer.phar install
Composer could not find a composer.json file in C:\php
To initialize a project, please create a composer.json file as described in the http://getcomposer.org/ "Getting Started" section

C:\php>php composer.phar install
Loading composer repositories with package information
Installing dependencies (including require-dev)
  - Installing monolog/monolog (1.2.1)
    Downloading: 100%

monolog/monolog suggests installing mlehner/gelf-php (Allow sending log messages to a GrayLog2 server)
monolog/monolog suggests installing ext-amqp (Allow sending log messages to an AMQP server (1.0+ required))
monolog/monolog suggests installing ext-mongo (Allow sending log messages to a MongoDB server)
Writing lock file
Generating autoload files

C:\Workspace\localhost\symfony>php.exe c:\php\composer.phar create-project symfony/framework-standard-edition c:\workspace\localhost\symfony\Symfony 2.4.1
Installing symfony/framework-standard-edition (v2.4.1)
  - Installing symfony/framework-standard-edition (v2.4.1)
    Downloading: 100%

Created project in c:\workspace\localhost\symfony\Symfony
Loading composer repositories with package information
Installing dependencies (including require-dev)
  - Installing jdorn/sql-formatter (v1.2.17)
    Downloading: 100%

  - Installing psr/log (1.0.0)
    Loading from cache

  - Installing twig/twig (v1.15.0)
    Downloading: 100%

  - Installing doctrine/lexer (v1.0)
    Downloading: 100%

  - Installing doctrine/annotations (v1.1.2)
    Downloading: 100%

  - Installing doctrine/collections (v1.1)
    Downloading: 100%

  - Installing doctrine/cache (v1.3.0)
    Downloading: 100%

  - Installing doctrine/inflector (v1.0)
    Downloading: 100%

  - Installing doctrine/common (v2.4.1)
    Downloading: 100%

  - Installing symfony/symfony (v2.4.1)
    Downloading: 100%

  - Installing symfony/icu (v1.0.0)
    Downloading: 100%

  - Installing doctrine/dbal (v2.4.2)
    Downloading: 100%

  - Installing doctrine/doctrine-bundle (v1.2.0)
    Downloading: 100%

  - Installing kriswallsmith/assetic (v1.1.2)
    Downloading: 100%

  - Installing symfony/assetic-bundle (v2.3.0)
    Downloading: 100%

  - Installing sensio/framework-extra-bundle (v3.0.0)
    Downloading: 100%

  - Installing doctrine/orm (v2.4.1)
    Downloading: 100%

  - Installing twig/extensions (v1.0.1)
    Downloading: 100%

  - Installing swiftmailer/swiftmailer (v5.0.3)
    Loading from cache

  - Installing symfony/swiftmailer-bundle (v2.3.5)
    Downloading: 100%

  - Installing monolog/monolog (1.7.0)
    Loading from cache

  - Installing symfony/monolog-bundle (v2.5.0)
    Downloading: 100%

  - Installing sensio/distribution-bundle (v2.3.4)
    Downloading: 100%

  - Installing sensio/generator-bundle (v2.3.4)
    Downloading: 100%

  - Installing incenteev/composer-parameter-handler (v2.1.0)
    Downloading: 100%

kriswallsmith/assetic suggests installing leafo/lessphp (Assetic provides the integration with the lessphp LESS compiler)
kriswallsmith/assetic suggests installing leafo/scssphp (Assetic provides the integration with the scssphp SCSS compiler)
kriswallsmith/assetic suggests installing ptachoire/cssembed (Assetic provides the integration with phpcssembed to embed data uris)
kriswallsmith/assetic suggests installing leafo/scssphp-compass (Assetic provides the integration with the SCSS compass plugin)
monolog/monolog suggests installing mlehner/gelf-php (Allow sending log messages to a GrayLog2 server)
monolog/monolog suggests installing raven/raven (Allow sending log messages to a Sentry server)
monolog/monolog suggests installing doctrine/couchdb (Allow sending log messages to a CouchDB server)
monolog/monolog suggests installing ruflin/elastica (Allow sending log messages to an Elastic Search server)
monolog/monolog suggests installing ext-amqp (Allow sending log messages to an AMQP server (1.0+ required))
monolog/monolog suggests installing ext-mongo (Allow sending log messages to a MongoDB server)
monolog/monolog suggests installing aws/aws-sdk-php (Allow sending log messages to AWS services like DynamoDB)
Writing lock file
Generating autoload files
Creating the "app/config/parameters.yml" file
Some parameters are missing. Please provide them.
database_driver (pdo_mysql):
database_host (127.0.0.1):
database_port (null): 3306
database_name (symfony):
database_user (root):
database_password (null): secretkanding
mailer_transport (smtp):
mailer_host (127.0.0.1):
mailer_user (null):
mailer_password (null):
locale (en):
secret (ThisTokenIsNotSoSecretChangeIt): 123456987456321
Clearing the cache for the dev environment with debug true
Installing assets using the hard copy option
Installing assets for Symfony\Bundle\FrameworkBundle into web/bundles/framework
Installing assets for Acme\DemoBundle into web/bundles/acmedemo
Installing assets for Sensio\Bundle\DistributionBundle into web/bundles/sensiodistribution

C:\Workspace\localhost\symfony>
enlarge
IDE: NetBeans vs phpStorm
Posted: 27 Nov 2013, 20:23pm - Wednesday
Before back in college, I used UltraEdit, then Notepad++ as my HTML JS, CSS and PHP editor. I even tried Dreamweaver and it sucks for me. I also tried Ecplise and its way heavy application, too slow to load. I've been using NetBeans IDE for a while now. I met a PHP programmer and mention about phpStorm and got curious. So I downloaded phpStorm 7.0 and tested it out myself. I still find NetBeans as the Best IDE. Though I like the UI of phpStorm, I find it so COOL (see screenshot below) but (geeezz!) its too pricy will cost you $99 for personal license. Loading performance, I still voted for NetBeans. Features like FTP, SSH, Git, SVN etc -- most likely they have both NetBeans and phpStorm.

netbeans_vs_phpstorm

 I guess, I felt the same with other PHP developers about NetBeans, phpStorm, Eclipse and other IDEs. See: http://www.warriorforum.com/programming-talk/637270-eclipse-vs-netbeans-vs-phpstorm.html
enlarge

Issue:

C:\localhost\projectApp>php composer.phar update
Loading composer repositories with package information
Updating dependencies                                 
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Root composer.json requires PHP extension ext-zend-opcache * but it is missing from your system. Install or enable PHP's zend-opcache extension.

Solution:

Edit your php.ini and add this:

zend_extension=C:/php/ext/php_opcache.dll

then uncomment ...

[opcache]
; Determines if Zend OPCache is enabled
;opcache.enable=1

; Determines if Zend OPCache is enabled for the CLI version of PHP
opcache.enable_cli=1

That's it! To confirm it, do:

C:\localhost\projectApp>php -v
PHP 7.4.20 (cli) (built: Jun  1 2021 20:31:10) ( ZTS Visual C++ 2017 x64 )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Xdebug v3.0.4, Copyright (c) 2002-2021, by Derick Rethans
    with Zend OPcache v7.4.20, Copyright (c), by Zend Technologies

enlarge
Free Planning Poker
Posted: 12 Jun 2021, 13:26pm - Saturday

Hello Agile/Scrum people ...

If you are looking for free planning poker, use http://www.freeplanningpoker.co.nz/ or http://www.freeplanningpoker.site/ or http://www.freeplanning.poker/ and there will be no ads or limitation of 5 users or 5 issues then try to force you to upgrade to premium. The limitation is like it can create 100 issues of each gameplay and of course limit to 8 players, more than that will be a conference already. So 8 users or players, cast a vote and get the score for your issues.

This application is used for team management amd planning for agile team.

enlarge

I recently encountered a weird error on my repo when I "git push" or "git pull" in Windows 7. But when I tried it on my Mac, Ubuntu & Windows 10, its working fine.

Windows 7 - PHPStorm Terminal - git pull

As shown above, that's the error I am getting when I pull/push. I tried the solution from others:

reference: https://stackoverflow.com/questions/4485059/git-bash-is-extremely-slow-on-windows-7-x64

But unfortunately it didn't resolve my problem. Somehow, it did made it a bit faster.

I already tried many things, but I cannot find any solution that works for my problem. I know that the issue is just in my PC, even tried emptying my hosts file still didn't work.

Then a lightbulb popup, maybe I should delete my current repo and checkout again. So I did and resolve my problem. I can pull and push after that.

enlarge
PHP: about NULL vs 0
Posted: 18 Sep 2017, 20:43pm - Monday
A client reported about the data wasn't populating... So I debug and took me hours to find out... Background: We have this enterprise system with legacy code and we created a QueryDriver class to make the legacy, Silex DBAL & CodeIgniter works and reusable. Behind the QueryDriver, it uses vsprintf() function.
$parcelData = [];
$jobVarObj = new JobsVarsTable();
$jobVarObj->setDrivers($this->getQueryDriver());
$prime_parcel = $jobVarObj->getVarValue($this->job_id, 'PRIMARY_PARCEL');

...

$q = "SELECT * FROM jobs_parcels WHERE JID = '%d' AND ID != '%d' AND Deleted IS NULL";
$sql = $this->getQueryDriver()->fetchAll($q, [$this->job_id, $prime_parcel]);
$parcel_data_list = $sql->getData();

In that codes above, the $parcel_data_list is always empty and I know there are 1 row results. 2 hours later... Note: $prime_parcel = null; // if does not exists in the records, will return literal null I just realised that printing vsprintf($q, [ $this->job, $prime_parcel ]) will gave me what I expected because when you sprintf() or vsprintf() the NULL to %d, this will convert to ZERO. But actually when I pass the query to our QueryDriver, %d and %s are actually converted to ? which the NULL become literal NULL in the query. Instead of "SELECT * FROM jobs_parcels JID = '123' AND ID != '0' AND DELETED IS NULL" then becomes "SELECT * FROM jobs_parcels JID = '123' AND ID != NULL AND DELETED IS NULL". So there will be no result. So lesson learn... Solution:
$parcelData = [];
$jobVarObj = new JobsVarsTable();
$jobVarObj->setDrivers($this->getQueryDriver());
$prime_parcel = (int)$jobVarObj->getVarValue($this->job_id, 'PRIMARY_PARCEL', 'n');

...

$q = "SELECT * FROM jobs_parcels WHERE JID = '%d' AND ID != '%d' AND Deleted IS NULL";
$sql = $this->getQueryDriver()->fetchAll($q, [$this->job_id, $prime_parcel]);
$parcel_data_list = $sql->getData();
Then it solves my 2hrs problem!!! Ok that's my entry for half of 2017... hehehe.. Cheers!
enlarge
Prendstah.com got A+ grade from ssllabs.com
Posted: 15 Dec 2014, 11:09am - Monday
I was curious how Sid Bachtiar got the high grade of his SSL Report. It challenge me and give me interest how to do it. So I did. Oh Yeah! Got the A+ SSL Report grade. prendstah_Aplus_on_ssllabs

SSL Test: https://www.ssllabs.com/ssltest/analyze.html?d=prendstah.com

 

skype_a-ssl

enlarge
Code Igniter: Cannot get POST values
Posted: 27 Mar 2014, 22:01pm - Thursday
I encountered this issue in Code Igniter that I cannot get the POST values. Some says its the .htaccess issue. I used same .htaccess with all my application and works fine. I was working on my new environment, Kali Linux, and realised that its the mod_rewrite module wasn't loaded and partly affects the .htaccess.
# cd /etc/apache2/mods-enabled/
# locate mod_rewrite
/usr/lib/apache2/modules/mod_rewrite.so
# touch rewrite.load
# nano rewrite.load
At the file:
LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so
Save the changes and restart apache. Hope this will help you... Pee coding!
enlarge
Top PHP Frameworks
Posted: 9 Dec 2013, 20:23pm - Monday
PHP and MySQL TimeZone Synchronization
Posted: 5 Nov 2013, 3:00am - Tuesday
We all know the PHP and MySQL holds different timezone... what if we want both PHP and MySQL sync together by adjusting your PHP code only... Here's the solution:
<?php

define('TIMEZONE', 'Australia/Brisbane');

@date_default_timezone_set(TIMEZONE);

$dt = new DateTime();

// get time offset
$offset = $dt->format("P"); 

// update mysql timezone
mysql_query("SET time_zone='$offset';");

?>
  Thanks to Craig Buckler... Reference: http://www.sitepoint.com/synchronize-php-mysql-timezone-configuration/
enlarge