Experience with my friend(utkarsh) parents

Utkarsh is my flat mate.recently his parents has visited our house in pune. What I’m impress about his parents visits is his mom’s kind nature. Now that I’m old enough to realize how much his mother has done for me and utkarsh even after she just landed in pune after 15 to 16 hours of journey. she’s someone i truly look up to. Her hard work throughout the 2 day to support us, taking care of us.

Perhaps, the one thing that is going to took me by surprise and also deeply touched me is the warm hospitality of her. she was our guest and we were suppose to ask any preferences for food or drink but it was totally a different experience thought 2 days. She make us feel like we were the guest at her home.

Here is small incident with me. it was utkarsh birthdays. So they went out side for family lunch and I was stayed at home and was busy in doing my some work. when they were came back, she insisted cook a lunch for me and this is second time she caught my special attention.

WordPress singleton instance practice

Today we will discuss the Singleton pattern, the most controversial creation pattern.
A Singleton is a global point of access for a resource that must have only one instance in the whole application: database connections, http streams, and similar objects are the typical examples of such a class.

This behavior is implemented trough a static method which returns a lazy-created instance, and by rendering the constructor private to avoid creation of an instance from outside the class code.

This is a simple example of a singleton implementation:

<?php 
class PR_SINEXAMPLE { 	

       /** 	 
       * Placeholder method 	 
       */ 	
       private function __construct() {           
          $this->setup();
       }

	/**
	 * Get a singleton instance of the class
	 */
	public static function factory() {
		static $instance = false;
		if ( ! $instance ) {
			$instance = new self();
		}
		return $instance;
	}

        /**
	 * Setup actions and filters
	 */
	public function setup() {
        }

}
global $pr_singleton;
$pr_singleton = PR_SINEXAMPLE::factory();

The problems of a Singleton class are the same of its non object-oriented equivalent: a global variable. The Api of Clients of the Singleton lies, because they do not declare in any signature that they are taking advantage of the Singleton’s capabilities; moreover, global mutable state is introduced and encapsulation is disregarded.

Calling stored procedure in wordpress using wpdb

Today I was get stuck while calling stored procedure in wordpress. Neither $wpdb->get_results nor $wpdb->get_results was working. I got the point somrthing was went wrong. The output of  $wpdb->show_errors() is nothing so there was not an error.

This is a create statement of my procedure I’m tried to called it using $wpdb

CREATE PROCEDURE posts_count(OUT @total_posts INT)
BEGIN
SELECT COUNT(*)  INTO total_posts FROM wp_posts;
END//

Okay so I get to knew while try and test try and test

$result = $wpdb->query("CALL posts_count(@total_posts)");
$result = $wpdb->get_results("SELECT @total_posts");
var_dump( $result );

So finally it working. It is returning me a correct output

array (size=1)
0 =>
object(stdClass)[361]
public '@total_posts' => string '19' (length=2)