Work with UUID type in PostgreSQL- An easy way

We can easily work with UUID data type in PostgreSQL. Here, I am describing the way how we make it.


Extension “uuid-ossp” must be installed.

Check the extension: SELECT * FROM pg_available_extensions;

If not available then run following query to add this: CREATE EXTENSION "uuid-ossp";

Verify using: SELECT * FROM pg_extension;

Create a sample table with UUID type primary key-

id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
age integer

Now insert into table “People”. Primary key id will be automatically inserted with UUID format value.
INSERT INTO People(age) VALUES (10);

Fetch data from “People” table-

Select * from People;

If you face following error “error: Relation ‘tableName’ does not exist” while you are working with SQL query (but table already in database) then to fix this just write table name in quotation mark i.e. “Book”.

Take a look on following links-

Why programmer/developer fails?

Have you thought why you are not a good programmer/developer? Just imagine, you already tried so many things but still no luck to make a smart application that would make you happy.

I have been working for years with developers from different regions and what actually I have found? I found that they were always trying to work with so many things at the same time. As a result, after few months trying they failed to reach a satisfactory stage!

I saw few of them fallen into depression, I inspired them to stop and review what they already learned and practiced. I inspired them to try with best tools and continue with that until reaching a satisfactory stage.

So, my suggestions are-

  1. Don’t try many things at same time.
  2. Take one, two, three sequentially (If web dev then- HTML5, CSS, JavaScript/jQuery, SQL, PHP/Ruby/Python etc.)
  3. Learn in deep and enjoy its beauty
  4. Try to make something nice using each tool
  5. Summarize your work, progress, goal and continue moving to next steps


Happy learning…

How to calculate difference between two dates in hour using PHP?

This is pretty easy thing but sometimes we forget actually how we can calculate this. PHP Manual is a root source for this solution but sometimes its also time consuming to search and find the procedure.

Here I am just writing to memorize if you forgot already 🙂

$ts1 = strtotime('03-09-2013 04:48');
$ts2 = strtotime('02-09-2013 12:12');
$diff = abs($ts1 - $ts2) / 3600;     

If you want to find difference in day/minute/seconds then you need to change something in above code. Its your challenge to find the way..

Yii Installation on IIS server: Application runtime path is not valid issue

After Yii installation on IIS then developer face problem to run the demo application. And following error message appear in-front of them

“Application runtime path “C:\inetpub\wwwroot\projectname\protected\runtime” is not valid. Please make sure it is a directory writable by the Web server process.”

To solve this issue

1. Open IIS manager and select the project folder name from all available sites

2. From right pane “Actions” please select “Edit Permissions”  and then give full permission to user “IUSR” and then save and restart IIS

Reload your URL and see the result.

Install, update and use Yii with WAMP server

Here I am going to post my Wiki post from Yii Framework forum. I hope this will help all.

Here I am describing how you can install and update Yii in WAMP sever.

Follow the following step by step procedures to find your destination-

Step 1: Assigning PHP engine location path in system variable

  • Go to “My Computer” ->Right click and select “Properties”
  • Click “Advanced system settings” from left pane
  • Under “Advanced” tab click on “Environment Variables”
  • Under “System variables” scroll down and find text “Path” then Double click on it
  • Now enter your PHP engine location on end of the “variable value” field

    i.e. for me I entered “C:\wamp\bin\php\php5.3.10”. Just enter location without double quotes

  • Click ok and finally exit from this.

Step 2: Create project folder under “www”

Just create a blank folder in “www” that should be your project name. i.e “bid” You can also make this using command window. For this-

  • Open command window
  • C:>cd wamp\www\
  • C:\wamp\www>mkdir bid

Step 3: Download Yii framework and put into www directory and install the framework for bid project

  • Go “” and download latest Yii framework zipped file
  • Unzip and rename folder to “yii”
  • Using command-
    • C:\wamp\www>cd yii\framework\
    • C:\wamp\www\yii\framework>yiic webapp C:\wamp\www\bid

      Create a Web application under ‘C:\wamp\www\bid’? [Yes|No] y

      Your application has been created successfully under C:\wamp\www\bid.

Now you are ready to browse your project by accessing the URL : http://localhost/bid/

If you want to use this installation for multiple project then just copy “bid” folder and past and rename with your project name. Its better if you make “bid” folder as your backup project folder then when you need to work with a new project then just you need to copy and past this folder and rename to your new project name.

If you want to install an updated version of Yii framework then please download updated version zipped folder from “” and unzip. After unzip the file just copy the framework folder and then go “yii” folder under “www” directory and just replace previous framework folder with latest one.

Enjoy and explore Yii………..

How to connect and use SQL Server 2008 database in ASP.Net MVC 4 EF code-first architecture

This is an important issue that sometimes beginner have faced when they start work with mentioned architecture.

I am going to discussed a very easy solution about this issue-

After create a project in ASP.Net MVC 4 then its comes up with complete hello world sample MVC web application with default database in project folder. So, when you want to use your database that already in SQL Server. ASP.Net MVC Entity Framework(EF) code-first technology always try to create a default database instead of connecting to your specified SQL Server database. And display a message “System.Data.ProviderIncompatibleException was unhandled by user code

To solve that issue
First: Go to Web.config file and then connectionString and update this entry by following way

<add name="MyDb" connectionString="Data Source=(local);Initial Catalog=MyDb;Integrated Security=True" providerName="System.Data.SqlClient"/>

This is for local SQL Server database with Windows Authentication. If you want other your specific database server then go to following website and find your suitable one.

Second: Open your model file and add/update following way (Here I am using User Model file)
public class UserDBContext : DbContext
//Add the name of your database connection to the base DbContext class
public UserDBContext(): base("MyDb")
public DbSet Users { get; set; }

You need to add that way for all model files in your project.

Hope you will find a better way.

How can use Yii TinyMCE extension on production

Sometimes developer face issues to use Yii TinyMCE extension on production server. Its stops showing anything on production except words “Text mode”

To use on production just follow few steps–
'htmlOptions'=>array('rows'=>6, 'cols'=>50, 'class'=>'tinymce'),

Because, server already compresses the data and extension try to compress again. As a result,  the browser does not understand this situation.

Now this will work on production environment.

How can use Yii Bootstrap GridView in your application

This is very easy. Just need to follow few things. I suggest to browse Yii Bootstrap site for more details.

$this->widget('bootstrap.widgets.TbGridView', array(
   'type'=>'striped bordered condensed',


       array('name'=>'last_name', 'header'=>'Name'),
       array('name'=>'email', 'header'=>'Email Address'),
       array('name'=>'mobile_phone', 'header'=>'Mobile Phone'),
       array('name'=>'city', 'header'=>'City'),
       'htmlOptions'=>array('style'=>'width: 50px'),


Display input element on dropdown selection in Yii

To display an input element on dropdown selection is very easy. Just follow few steps-
Using JavaScript:
Selection dropdown 1:

<div class="row">  
   <?php echo $form->labelEx($model,'status'); ?>

   <?php echo $form->dropDownList($model,'status',
      array('onchange'=>'return checkStatus(this.value)'));

   <?php echo $form->error($model,'status'); ?>

    Hidden div. Will active if selection is true
    <div id="hiddendiv" style="display:none">                 
        <div class="row">
           <?php echo $form->labelEx($model,'category'); ?>
           <?php echo CHtml::activeDropDownList($model,'category', 
                array('prompt'=>'Select') ); ?>
           <?php echo $form->error($model,'category'); ?>
function checkStatus(obj)
       return false;               
       return false;                
By Using Yii Ajax-

In View
        <?php echo $form->labelEx($model,'status'); ?>

        <?php echo $form->dropDownList($model,'status',
        array('0' =>'In active', '1'=> 'Active'),

        array( 'onChange' => 'javascript:description()', 
        <div id="status_id"></div>
        <?php echo $form->error($model,'status'); ?>

    In Controller-
    public function actionfunctionName()
           //For only text field
           //echo CHtml::textField("Employment",'applying_position'); 

           // For Dropdownlist

           echo $form->dropDownList($model,'status',

Hope that will help us.

Create custom Input validation rules in Yii model for dependent input field

Suppose we want to create a dependent input validation rule in Yii model for dependent 2 input field. Field one is status and field two is reason. If user select a status from dropdown list then they must be fill-up reason field. If not then it will show a error message.

In model rules-

public function rules()
   return array(
   array('status', 'reasonValidators'),

and validation function-

public function reasonValidators()
  if ((int)$this->status=="Yes")
    $labels = $this->attributeLabels(); // Getting labels of the attributes
       $this->addError("reason", $labels["reason"]." cannot be blank.");
    // More dependent on type can be written here