Category Archives: PHP

Laravel 5.1 Useful Resources





Leave a comment

Posted by on September 12, 2016 in Laravel, PHP




Leave a comment

Posted by on January 8, 2016 in PHP


Change Database Collation with PHP

This little sql statement can change the collation in your database including tables, columns and everywhere. This is something phpMyAdmin can not handle completely.

Credits goes to original poster.

$conn1=new MySQLi("localhost","root","","exam_db");
    echo mysqli_connect_error();
$res=$conn1->query("show tables") or die($conn1->error);
    $conn1->query("ALTER TABLE $tables[0] CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci") or die($conn1->error);
echo "The collation of your database has been successfully changed!";


Leave a comment

Posted by on October 2, 2015 in PHP




Leave a comment

Posted by on September 14, 2015 in Codeigniter



DataTables Server Side Processing with CodeIgniter



In this tutorial, we will see how to use popular dataTables with CodeIgniter framework. Note that, pagination is done in client side for this tutorial. Hence this example is not ideal for a big data set. Handling pagination in server side will be discussed in  a future tutorial.

Table format

                             <th>Need identified thru</th>
                                        <th>Total Estimate</th> 
                                        <th class="no-sort"></th>
                                        <th class="no-sort"></th>



Initializing and fetching data with ajax

    $(document).ready(function() {
            "ajax": "<?php echo base_url('test/get_json'); ?>",
            "pageLength": <?php echo $this->config->item('results_per_page'); ?>,
            "order": [[ 0, "desc" ]],
            "aoColumnDefs": [
                { "bVisible": false, "aTargets": [0] },
                    "bSortable": false,
                    "aTargets": ["no-sort"]  
            "dom": 'T<"clear">lfrtip',
            tableTools: {
                "sSwfPath": "<?php echo base_url("plugins/data_tables/extensions/TableTools/swf/copy_csv_xls_pdf.swf"); ?>"

Test Controller

class Test extends CI_Controller {
public function get_json() {
        $results = $this->test_model->load_grid();
        $data = array();
        foreach ($results  as $r) {
            array_push($data, array(
                anchor('test/view/' . $r['id'], 'View'),
                anchor('test/edit/' . $r['id'], 'Edit')

        echo json_encode(array('data' => $data));


class Test_model extends CI_Model {
public function load_grid() {
        $this->db->select("$this->tbl_urgent_needs.unid,$this->tbl_urgent_needs.year,$this->tbl_urgent_needs.needi,$this->tbl_urgent_needs.total_cost,$this-> AS mname,$this-> AS rname");
        $this->db->join("$this->tbl_roads", "$this->tbl_roads.rid = $this->tbl_urgent_needs.rd_id");
        $this->db->join("$this->tbl_maintenance_type", "$this-> = $this->tbl_urgent_needs.maint_type_id", "left");
        $this->db->order_by("$this->tbl_urgent_needs.unid", 'ASC');

        $query = $this->db->get();
        return $query->result_array();


Posted by on May 20, 2015 in Codeigniter, PHP



iPhone Push Notifications PHP Server

iPhone Push Notifications PHP Server

$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', YOUR_.PEM_FILE);
stream_context_set_option($ctx, 'ssl', 'passphrase', YOUR_PASSPHRASE);

$fp = stream_socket_client(
        'ssl://', $err, $errstr, 60, STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT, $ctx);

if (!$fp) {
    exit("Failed to connect: $err $errstr<BR><BR>");

echo 'Connected to APN<BR>';

// Create the payload body
$body['aps'] = array(
    'badge' => +1,
    'alert' => 'Testing push notifications',
    'sound' => 'new_wall_paper.wav',
    'action-loc-key' => 'OK'

$payload = json_encode($body);

for ($i = 0; $i < count($tokens); $i++) {
    $msg = chr(0) . pack('n', 32) . pack('H*', $tokens [$i]) . pack('n', strlen($payload)) . $payload;
    fwrite($fp, $msg, strlen($msg));

echo "Completed sending messages";

1 Comment

Posted by on July 25, 2014 in iphone, PHP



Passing Multiple Parameters to Form Validation Custom Callbacks in Codeigniter

Codeigniter Custom Callbacks

Codeigniter Custom Callbacks

CI natively only allows for  single parameter in custom callbacks. For an instance see the following code.

('hstate', 'State', 'required|callback_suburb_check[' . $suburb . ']');

If you need to pass multiple parameters, you have several options. Obviously you can change CI behaviour by subclassing the core library. But in this tutorial we follow the less pain approach. That ‘s to access required parameters via POST variables within your custom callback function. They are still available in this scope.

There is another way using your PHP string handling knowledge. Just formatting all the parameters as single string and passing to the callback function.

$parameters = 'first_arg' . '||' . 'second_arg' . '||' . 'third_arg';
('some_field', 'Some Field Name', 'callback__my_callback_function['.$parameters.']');  

Then in your callback,

function _my_callback_function($field_value, $second_parameter){
    list($first_param, $second_param, $third_param) = split('||', $second_parameter);
Leave a comment

Posted by on June 30, 2014 in Codeigniter


Tags: ,