Author Archives: admin

Return format json

select a.f_name, array_to_json(array(select d_name
from hid_department
where d_code_induk=a.f_code AND d_name ILIKE ‘%Cari%’)) as department
from hid_faculty a
where f_code=’xxxxx’ AND f_name ILIKE ‘%Cari%’;

Return format string

select f_name, array_to_string(array(select d_name
from hid_department
where d_code_induk=’xxxxx’),’|’) as department
from hid_faculty
where f_code=’xxxxx’;

Ionic 3 Push Notification

Keperluan :

  1. Google app id/ sender id(From firebase console)
  2. Server key(From firebase console)
  3. One Signal appId (From One Signal Dashboard after creating one signal application)

Google app id/ Sender id

  1. Login (
  2.  “Add project”
  3. Isi maklumat projek.
  4. Klik gear icon > Project setting> Cloud Messaging. Dapatkan server key and sender id bawah tab cloud messaging tab.

Ionic 3 dengan One Signal Push Notification Service

  1. (
  2. Selepas login create new app
  3. Create new One Signal application.
  4. Klik app yang hendak buat notifikasi
  5. Pilih (Google Android GCM) dan NEXT.
  6. Masukkan server key and google project number(sender id or Google app id)
  7. Kemudian pilih Ionic and NEXT.
  8. Akan dapat One Signal App Id. Id yang akan digunakan dalam ionic. Klik “check subscribed users” untuk test.

Push notification in ionic 3 application.

Install the Cordova and Ionic Native plugins:

$ ionic cordova plugin add onesignal-cordova-plugin
$ npm install --save @ionic-native/onesignal


var notificationOpenedCallback = function(jsonData) {
 alert('notificationOpenedCallback: ' + JSON.stringify(jsonData));
 .startInit("ff919ce0-8b1e-4e97-8215-04aef5118800", "286346003172")


node -v –> version node
npm -v

install ionic
-> npm install -g ionic cordova

create project
–> ionic start MyDecApp blank

start service kat dalam folder project
–> ionic serve

create file baru
–> ionic g page Profile

tgk template
–> ionic start –list

generate provider
–> ionic g provider webservices

remove platform android
–> ionic cordova platform remove android

add platform android
–> ionic cordova platform add android

built android
–> ionic cordova build android

tukar icon
–> ionic cordova resources

built android
google play
–> ionic cordova build android –prod –release

keytool -genkey -v -keystore my-release-key.jks -keyalg RSA -keysize 2048 -validity 10000 -alias my-alias <– run sekali je kunci ni

keytool -genkey -v -keystore upminfokey.jks -keyalg RSA -keysize 2048 -validity 10000 -alias upminfo

jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore my-release-key.jks android-release-unsigned.apk my-alias

jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore upminfokey.jks android-release-unsigned.apk upminfo

zipalign -v 4 android-release-unsigned.apk HelloWorld.apk

zipalign -v 4 android-release-unsigned.apk UPMScanner.apk

apksigner verify HelloWorld.apk

apksigner verify UPMScanner.apk

Mysql to Mysqli

How to Convert MySQL to MySQLi: MySQL vs MySQLi

If you are not aware by now that the MySQL extension is being removed in the PHP 7 release, then let me be the first to welcome you to the current century.

In this article I will discuss some of the techniques that I use to make the process of migrating MySQL to MySQLi as painless as possible by using the MySQLi procedural style which is very similar to the MySQL extension.

PHP MySQLi Connect Alternative on PHP7 mysql_connect mysqli_connect: Using a Resource versus new mysqli Object

The first thing we need to look at is that MySQL is a resource and MySQLi is an object. To migrate our code, we really do not need to understand the technical difference, however we must understand that they are different.

The first thing we usually do with MySQL is to connect to and select a database, so let’s take a look at mysql_connect and mysql_select_db.

$connection = mysql_connect( 'host', 'username', 'password', new_link,flags);
$database = mysql_select_db( 'database', $link);

$connection is a MySQL link identifier to the resource and $database is just a boolean variable that will contain true on success or false on failure. In most situations your host will be localhost and you will only have supplied your username and password.

Now let’s take a look at its counter-part in MySQLi, mysqli_connect.

$connection = mysqli_connect( 'host', 'username', 'password', 'database', 'port', 'socket');

$connection is a link to the MySQLi object for this connection. If your connection using mysql only uses the host, username and password, then updating your code is as simple as changing mysql_connect to mysqli_connect.

You could also go ahead and add the database to connect to right there in the mysqli_connect parameters and eliminate mysql_select_db. This is OK if there is no variable to store the result, however if a variable was used it is possible that there may be logic somewhere deep in the code that will be using this variable to check the valid connection to the database. In these instances I recommend using mysqli_select_db.

$database = mysqli_select_db($link, 'database');

With MySQL, you where not required to provide a link, the last opened connection was used if the link was not specified. When using MySQLi, the link is required and as you can see, it is now the first parameter.

Using our examples, this $link is connection and our database name would remain the same. $database is still a boolean variable, so if it is referenced anywhere else in the code, it will operate as expected.

In case your connection is not the simple standard one we have just gone through, we need to go back and look at mysql_connect again. The host parameter may contain a port number, localhost:3307, or a socket, localhost:/path/to/mysql.sock. When migrating these to mysqli_connect, you would simply move the port or socket to the port and socket parameters.

You may have the new_link flag set, which allowed MySQL to open a new connection instead of using the one previously opened. Then whichever link was being used would be named as the link parameter. When migrating these, we simply create a new MySQLi object with the same link name. To illustrate this…

$connection2 = mysql_connect( 'host', 'username', 'password', true);

would become

$connection2 = mysqli_connect( 'host', 'username', 'password');

You may also have client flags set, MySQLi does not use these and they can be safely removed when generating the MySQLi connection.

You may have a variation to the mysql_connect to establish a persistent connection, which is mysql_pconnect. To establish the same persistent connection in MySQLi, you simply prepend the host with a p: prefix, so localhost becomes p:localhost.

In MySQL we could use mysql_error and mysql_errno to determine if there was an error connecting. Since the MySQLi replacements for these use the link to the object and even if there was a problem connecting an object is returned, we have to use mysqli_connect_error and mysql_connect_errno.

With both of these you do not provide a link, which allows them to be used to check the last connection attempt.

OK, I did promise this would be simple and now that we have gotten a proper MySQLi connection, we have the hardest part out of the way.

Migrating mysql_select_db, mysql_query, mysql_fetch_array, mysql_list_fields and other Procedural Methods to MySQLi

MySQLi procedural methods use a parameter that references either an object link or a result object. We have seen the reference to the object link when we dealt with mysqli_select_db. The result object is similar to a MySQL result returned from a query, for example.

Many of the methods in MySQL have very similar procedural methods in MySQLi, and are as simple to migrate as adding the i to mysql and adding or moving the link or result to the first parameter. Remember that MySQLi requires the link for those methods that reference a link. In the following list, the MySQL statement is followed by the replacement MySQLi procedural method.

mysql_affected_rows -> mysqli_affected_rows($link)
mysql_close -> mysqli_close($link)
mysql_data_seek -> mysqli_data_seek( $result, $offset)
mysql_errno -> mysqli_errno( $link)
mysql_error -> mysqli_error( $link)
mysql_fetch_array -> mysqli_fetch_array( $result, $type)
mysql_fetch_assoc -> mysqli_fetch_assoc( $result)
mysql_fetch_lengths -> mysqli_fetch_lengths( $result )
mysql_fetch_object -> mysqli_fetch_object( $result, $class, $params)
mysql_fetch_row -> mysqli_fetch_row( $result)
mysql_field_seek -> mysqli_field_seek( $result, $number)
mysql_free_result -> mysqli_free_result(result)
mysql_get_client_info -> mysqli_get_client_info( $link)
mysql_get_host_info -> mysqli_get_host_info( $link)
mysql_get_proto_info -> mysqli_get_proto_info( $link)
mysql_get_server_info -> mysqli_get_server_info( $link)
mysql_info -> mysqli_info( $link)
mysql_insert_id -> mysqli_insert_id( $link)
mysql_num_rows ->  mysqli_num_rows( $result)
mysql_ping -> mysqli_ping( $link)
mysql_query -> mysqli_query( $link, $query)
mysql_real_escape_string -> mysqli_real_escape_string( $link)
mysql_select_db – > mysqli_select_db( $link, $database)
mysql_set_charset -> mysqli_set_charset( $link, $charset)
mysql_stat -> mysqli_stat( $link)
mysql_thread_id -> mysqli_thread_id( $link)

Dealing With the More Difficult Methods

The bad news, not all methods are easy to migrate as the ones listed above. The good news, these methods are not that common so you may not even have to deal with them. These more difficult methods will require some discussion, so we will go through them one at a time.

mysql_client_encoding -> mysqli_character_set_name( $link)

This is a simple name change.


This statement is replaced with the mysqli_query method using the CREATE DATABASE sql…

$result = mysqli_query( $link, 'CREATE DATABASE database_name' );


This statement is used in conjunction with the mysql_list_dbs statement to get the requested row from a given result. To migrate it to MySQLi, we have to use the mysqli_data_seek method to locate the requested row and then mysqli_fetch_row to return requested row.

$data = mysql_db_name( $result, $row);


mysqli_data_seek( $result, $row);
$fetch = mysql_fetch_row( $result );
$data = $fetch[0];


In MySQL, this statement selects a database and runs the query. To migrate it to MySQLi, we use the mysqli_select_db method to select the database and then the mysqli_query method to run the query and return the result.

$result = mysql_db_query( 'database', 'query');


mysqli_select_db( 'database' );
$result = mysqli_query( 'query' );


This statement is replaced with the mysqli_query method using the DROP DATABASE sql…

$result = mysqli_query( $link, 'DROP DATABASE database_name');

mysql_escape_string -> mysql_real_escape_string( $link, ‘string’)

This is a simple name change.

mysql_fetch_field -> mysqli_fetch_field( $result )

If this statement does not contain the optional offset parameter, then it is a simple name replacement to migrate. If the offset parameter is included, then we have to loop through the result until we find the requested offset.

$fetch = mysql_fetch_field( $result, 5);


for(x=0; x<5; x++) {
  mysqli_fetch_field( $result );
$fetch = mysqli_fetch_field( $result );


In MySQL, these statements return the length, name or table of the specified field. To migrate it we use the MySQLi method mysqli_fetch_field_direct to return an object containing the field data and then return the field length, name or table from that object.

$length = mysql_field_len( $result, 5);
$name = mysql_field_name( $result, 5);
$table = mysql_field_table( $result, 5)


$fieldInfo = mysqli_fetch_field_direct( $result, 5);
$length = $fieldInfo->length;
$name = $fieldInfo->name;
$table = $fieldInfo->table;


This statement is replaced with the mysqli_query method using the SHOW DATABASES sql…

$result = mysqli_query( $link, 'SHOW DATABASES');


This statement is replaced with the mysqli_query method using the SHOW COLUMNS FROM sql…

$result = mysqli_query( $link, 'SHOW COLUMNS FROM table_name' );

mysql_list_processes -> mysqli_thread_id( $link )

This is a simple name change.


This statement is replaced with the mysqli_query method using the SHOW TABLES FROM sql…

$result = mysqli_query( $link, 'SHOW TABLES FROM database_name');

mysql_num_fields -> mysqli_field_count( $link )

This statement references the result in MySQL and is replaced with the mysql_field_count method which references the link.


In MySQL, this statement fetches a specified row and optional field from a given result. To migrate it we use the mysqli_data_seek to locate the row and loop through the fields using mysqli_fetch_field to return the field.

$fetch = mysql_result( $result, 3, 'field');


mysql_data_seek($result, 3);
if( !empty($field) ) {
  while($finfo = mysqli_fetch_field( $result )) {
    if( $field == $finfo->name ) {
      $f = mysqli_fetch_assoc( $result );
      $fetch =  $f[ $field ];
} else {
  $f = mysqli_fetch_array( $result );
  $fetch = $f[0];


In MySQL, this statement returns the table name in the row of a specified result. To migrate it we use the mysqli_data_seek method to locate the specified row and fetch the name using the mysqli_fetch_array method.

$name = mysql_tablename( $result, 3 );


mysqli_data_seek( $result, 3 );
$f = mysql_fetch_array( $result );
$fetch = $f[0];


This statement is replaced with the mysqli_query method with the result mode set to MYSQLI_USE_RESULT…

$result = mysqli_query($link, 'query', MYSQLI_USE_RESULT);

The Red-Headed Step-Children

First off I would like to point out that I have nothing against red-headed people or step-children in general. In the United States this is a phrase which refers to a problem that nobody wants to deal with and I just do not know what a politically correct replacement would be, so we are stuck with it.

There are 2 MySQL statements that are a real pain to deal with since they use flags and types that are not supported in MySQLi the same way they where in MySQL. To get these to work, we have to create our own.


$resultFlags = mysql_field_flags( $result, 3);


$flags = array();
$constants = get_defined_constants( true );
foreach ($constants['mysqli'] as $c => $n)
 if (preg_match('/MYSQLI_(.*)_FLAG$/', $c, $m))
  if (!array_key_exists($n, $flags))
   $flags[$n] = $m[1];
  $flags_num = mysqli_fetch_field_direct( $result, $field_offset )->flags;
  $result = array();
  foreach ($flags as $n => $t)
   if ($flags_num & $n)
    $result[] = $t;
  $returnFlags = implode(' ', $result);
  $returnFlags = str_replace( 'PRI_KEY', 'PRIMARY_KEY', $returnFlags);
  $returnFlags = strtolower($returnFlags);


$resultType = mysql_field_type( $result, 4);


$type_id = mysqli_fetch_field_direct( $result, $field_offset)->type;
$types = array();
$constants = get_defined_constants(true);
foreach ($constants['mysqli'] as $c => $n)
 if (preg_match('/^MYSQLI_TYPE_(.*)/', $c, $m))
  $types[$n] = $m[1];
$resultType = array_key_exists( $type_id, $types ) ? $types[$type_id] : NULL;

PHP Java Bridge

———- DOWNLOAD ———–
1. Download tomcat 7.077
2. Download EasyPHP / Xampp / Wampp
3. Download JavaBridge and unpack the files / download JavaBridge.war file and save it in any folder.


4. Install EasyPHP and test the runable.

5. Edit php.ini ,turn on setting -> allow_url_include = On;

6. Configure the environment variable under “PATH” by placing the setup location i.e. “C:\Program Files (x86)\EasyPHP5.2.10\php”

7. To check the PATH variable ifworking correctly run the “command prompt” (cmd) and type this

c:\ php-cgi -v

C:\>php-cgi -v
PHP 5.2.10 (cgi-fcgi) (built: Jun 17 2009 16:16:54)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2009 Zend Technologies

Should appear

——- INSTALL TOMCAT 7.077 ——————

8. Install Tomcat 7.077
– configure the tocat user on “tomcat-users.xml” file look for it under the “apache-tomcat-7.0.77\conf” folder.

<role rolename=”manager-gui”/>
<role rolename=”admin-gui”/>
<role rolename=”manager-script”/>
<user username=”tomcat” password=”tomcat” roles=”manager-gui,admin-gui,manager-script”/>
<user username=”both” password=”tomcat” roles=”tomcat,role1″/>
<user username=”role1″ password=”tomcat” roles=”role1″/>

9. Run localhost:8080

10. While the tomcat is running..
go to “apache-tomcat-7.0.77\webapps” and copy paste the “JavaBridge.war” file into it.

11 . Refresh thhe tomcat / restart the tomcat server.

12. Go to localhost:8080/JavaBridge and you should be able to see the screen as shown.

13. Test php with new project and index.php file by including the following code.
$System = java(“java.lang.System”);
echo $System->getProperties();



Training with Mr Krishnan VSK in UPM 19/05/2017

How to permanently enable Cookies in Lynx text browser – Disable accept cookies prompt in lynx console browser

To enable the persistent cookies in lynx, one needs to edit lynx.cfg on different GNU / Linux and BSD* distributions lynx.cfg is located in different directory.

Most of the lynx.cfg usual locations are /etc/lynx/lynx.cfg or /etc/lynx.cfg as of time of writting this post in Debian Squeeze GNU / Linux the lynx.cfg is located in /etc/lynx-cur/lynx.cfg, whether for FreeBSD / NetBSD / OpenBSD users the file is located in /usr/local/etc/lynx.cfg

What I did to allow all cookies is open lynx.cfg in vim edit and change the following lines:







uncomment it to:


c) next, change



Onwards opening any website with lynx auto-accepts the cookies.

ionic push notification

  1. ionic start MyApp tabs
  2. ionic add ionic-platform-web-client
  3. ionic plugin add phonegap-plugin-push –variable SENDER_ID={{ Project number google }}
  4. ionic io init
  5. ionic config set dev_push false
  6. ionic config set gcm_key {{ Project number google }}
  7. ionic platform add android
  8. ionic build android
  9. ionic run android –device

full note :

Start ionic

  1. node install
  2. command
    1. npm install -g ionic
    2. npm install -g gulp
    3. npm install -g bower
    4. npm install -g cordova
  3. android sdk/studio & xcode (mac only)
  4. download chrome livereload plugin :

Test :

  • ionic -v
  • gulp -v
  • bower -v

// bower – package manager front end framework
bower install jquery
bower update jquery


New Project

  1.  ionic start gstcalculator
    1. Create an account to send Push Notifications and use the Ionic View app?
      (Y/n): n
  2.  ionic serve
    1. Multiple addresses available.
      Please select which address to use by entering its number from the list below:
      1) (VMware Network Adapter VMnet1)
      2) (VMware Network Adapter VMnet8)
      3) (Wi-Fi)
      4) localhost
      Address Selection: 4 <– choose localhost
  3. quit @ q
  4. ionic serve –lab
    1. Untitled
  5. Open atom
    1. Change title
  6. Ubah CSS
  7. Insert input type
    1. Untitled
  8. Insert checkbox and button
    1. <ion-content>
      <div class=”list list-inset”><div class=”item item-input”>
      <input type=”text” placeholder=”Amount”>
      <!– .item.item-toggle{Inclusive GST?}>lable.toggle toggle-assertive>input:checkbox+.track>.hanlde –>
      <div class=”item item-toggle”>
      Inclusive GST?
      <label for=”” class=”toggle toggle-assertive”>
      <input type=”checkbox” name=”” id=””>
      <div class=”track”>
      <div class=”handle”></div>
      <div style=”text-align:center”>
      <button class=”button icon-left ion-calculator button-positive”>
  9. Buka app.js tambah controller
    angular.module(‘starter’, [‘ionic’]).controller(‘GstCtrl’, function($scope){$ = {
    amount: 0
    }; // user input$scope.calculateGst = function (){
  10.  Terima dari controller
    1. Untitled
  11. Calculate di controller
    1. Untitled
    2. .controller(‘GstCtrl’, function($scope){$ = {
      amount: 0,
      inclusiveGst: false,
      subTotal: 0,
      gstAmount: 0,
      grandTotal: 0
      }; // user input$scope.calculateGst = function (){
      $ = $ / 1.06;
      $ = $ * 0.06;
      $ = $;
      else {
      $ = $;
      $ = $ * 0.06;
      $ = $ * 1.06;
  12. Papar hasil dari controller
    1. Untitled
    2. <div class=”list list-insert”>
      <div class=”item”>
      Sub Total
      <span class=”item-note” ng-bind=”data.subTotal | currency:’RM ‘:2″>
      <i class=”icon ion-search placeholder-icon”></i>
      <div class=”item”>
      GST Amount
      <span class=”item-note” ng-bind=”data.gstAmount | currency:’RM ‘:2″>
      <div class=”item”>
      Grand Total
      <span class=”item-note” ng-bind=”data.grandTotal | currency:’RM ‘:2″>

Mari kenal Javascript

console.log(‘Hello World’);

// single js comment

line commment */

/* js statements :
value, operator, expression, keyword & comment */

// variable declaration
var x = 1; // number (integer)
var y = 1.2; // number(float)
var s = “Hello”; // string
var p = ‘World’; // string

// = assingment operator
// arithmetic operator
var a = 6;
var b = 2;
console.log(a + b); // 8
console.log(a – b); // 3
console.log(a / b); // 3
console.log(a * b); // 12
console.log(s + ” ” + p); // concat

// case sensitive
var firstName = ‘Hezrul’;
console.log(firstName); // undefined

var last_name = ‘Hezrul’;
var state = “Negeri Sembilan”;
console.log(last_name + ‘ ‘ + state);

var $country = “malaysia”;
var _price = 5.60;
console.log($country + ‘ ‘ + _price);

// string operator
var text1 = “John”;
text1 += ” Doe”; // text1 = text1 + ” Doe”;


// comparison operator
// >, <, >=, <=, ==, !, !=, ===, !==
if(a > b) {
console.log(“a greater than b”);

if(1 === “1”) { // not true
console.log(“equal value and equal type”);
}else {
console.log(“equal value”);
//ternary operator
// variableName = (condition) ? true : false
var age = 10;
var voteable = (age < 18 ) ? “Too young” : “Old enough”;
console.log(voteable); // Too young

// array
var cars = [“Proton”, “Volvo”, “BMW”];
// var cars = new Array(“Proton”, “Volvo”, “BMW”);

// access the elements of an Array

var person = [‘John’, ‘Doe’, 46];
console.log(“Name : ” + person[0] + ‘ ‘ + person[1] + “\nAge : ” + person[2] );


// array properties & methods
console.log(cars.length); // 3
console.log(person); //[“John”, “Doe”, 46, “US”]
console.log(person); //[“John”, “Doe”, 46]

// associative array
var student = [];
student[‘firstName’] = “Hezrul”;
student[‘lastName’] = “Mifzal”;
console.log(student.length); //0
console.log(student[0]); // undefined
console.log(student[‘firstName’]); //Hezrul

// loop
for (i = 0; i < cars.length; i++) {

cars.forEach(function(element, index){ // php foreach($arr as $key => $value)
console.log(index + ” => ” + element);

//isStrind, isInt,
if (Array.isArray(cars)) {
console.log(‘variable cars is array’);

if(cars instanceof Array){
console.log(‘variable cars is array’);

console.log(typeof cars); // object