PHP: about NULL vs 0

Info.Tech, PHP, Silex Framework, SQL: Structured Query Language, Web Development Comments Off on PHP: about NULL vs 0

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!

Prendstah.com got A+ grade from ssllabs.com

Administration, Info.Tech, PHP, Web Development Comments Off on Prendstah.com got A+ grade from ssllabs.com

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

Selwyn District Council Consents

Info.Tech, PHP, Web Development Comments Off on Selwyn District Council Consents

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)

PHP Deployment Tool: Mage

Info.Tech, PHP, Web Development Comments Off on PHP Deployment Tool: Mage

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

Code Igniter: Cannot get POST values

Administration, Code Igniter, Info.Tech, PHP, Web Development Comments Off on Code Igniter: Cannot get POST values

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!

Allow postfix to send email with different sender from SMTP account

Administration, Info.Tech, Linux System Administration, PHP, Web Development Comments Off on Allow postfix to send email with different sender from SMTP account

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…

Top PHP Frameworks

Info.Tech, PHP, Web Development Comments Off on Top PHP Frameworks
Top 5 PHP Frameworks Infographic
From: www.zfort.com

[Solution] 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.

Info.Tech, PHP, Web Development Comments Off on [Solution] 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.

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: JpGraph Fonts (1293)

And that should solve the problems… 🙂

Samples:

progression_graph_1386128392 progression_graph_1386188039

IDE: NetBeans vs phpStorm

Info.Tech, PHP, Web Development Comments Off on IDE: NetBeans vs phpStorm

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

PHP and MySQL TimeZone Synchronization

Info.Tech, PHP, SQL: Structured Query Language, Web Development Comments Off on PHP and MySQL TimeZone Synchronization

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/

WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in