Latest Posts

Posted by Thurein on 23rd February 2012

How to use separated sessions based on application in symfony

Currently, I’m playing with symfony mvc framework. In my current project is developing used by symfony and that’s have 2 app which are backend and frontend. But the project requirement is – these apps have to use their own session. So I separated the session in application level configuration as like follow -

In apps/backend/config/factories.yml

#apps/backend/config/factories.yml

all:

  ... # other configurations

  storage:
    class: sfSessionStorage
    param:
      session_name: backend_session

In apps/frontend/config/factories.yml

#apps/frontend/config/factories.yml

all:

  ... # other configurations

  storage:
    class: sfSessionStorage
    param:
      session_name: frontend_session

That all it is. Hope it useful for someone

Posted by Thurein on 4th March 2011

reCAPTCHA plugin for php codeigniter

I’m playing around with codeigniter frameworks these days. One of my client requested to put reCAPTCHA into CI frameworks. So, I have tried to convert from original reCAPTCHA php plug-in to codeigniter library. So, I would like to share this library. I hope it useful for someone.

To use this library, you just need to follow by under following instruction :

Firstly, you have to move Recaptcha.php file into CI file structure system/application/libraries/
Use following code to load that library -

$this->load->library('recaptcha');

Then you have to set keys. Sometime you just need to set only one public key. So, just set public key only.
To set the keys

// Get a key from https://www.google.com/recaptcha/admin/create
$this->recaptcha->set_key ('XXXXXXXXXX Key XXXXXXXXX' ,'public') // For public key
$this->recaptcha->set_key ('XXXXXXXXXX Key XXXXXXXXX' ,'private') // For private key

Continue Reading

Posted by Thurein on 1st December 2010

Difference between php mysql functions mysql_fetch_object(), mysql_fetch_assoc() and mysql_fetch_array()

Some of my friends are asked me. What’s difference between php functions mysql_fetch_object(), mysql_fetch_assoc() and mysql_fetch_array()? and how to use it ? If you also don’t known about it , please have a look example codes below. I think you would understand it.

mysql_fetch_object()

while ($each= mysql_fetch_object($result)) {
    echo $each->first_name;
    echo $each->last_name;
}

mysql_fetch_assoc()

while ($each= mysql_fetch_assoc($result)) {
    echo $each["first_name"];
    echo $each["last_name"];
}

mysql_fetch_array()

while ($each= mysql_fetch_array($result)) {
    echo $each[0];
    echo $each[1] ;
}
Posted by Thurein on 21st May 2010

Get Unlimited Parent and Child in PHP

Well, let me ask you first. Have you already known about recursion? If not, recursion mean reuse function in this function.

How is it ? For eg Like

function one_function ($var){
           one_function(332);
}

OK , So , how to related with this post title ? I would like to say absolutely related with recursion. Let’s say, we would like to create category with parent and child.so, we have one table in database, category table. Table Structure Like:

idnamep_id
1Main Parent0
2Sub Parent1
3Child2
4Parent 20
5Child 24
6Child 34
7Child 45

Continue Reading

Posted by Thurein on 7th April 2010

MySQL next and previous record of the current record

I have thought a lot these days what I should write some tips for beginner. Now, I got it. Have you ever noticed when you visiting and reading on some blogs? You will see previous and next links of current post. I don’t mean pagination links. If you have seen , have you ever thought how to retrieve those data from MySQL ? OK , If you haven’t thought and tried yet. Let’s see how to do it.

Let says, we have user table. Normally, we write SQL query like :

SELECT * FROM user WHERE user_id = 111

OK, If your user_id is added by auto increment, it’s simply write 111 – 1 and 111 + 1 in your program. If not, how could we got it?
Let’s see.

SELECT *,
(SELECT user_id FROM user WHERE user_id < u.user_id ORDER BY user_id DESC LIMIT 1) AS user_prev,
(SELECT user_id FROM user WHERE user_id > u.user_id ORDER BY user_id ASC LIMIT 1) AS user_next
FROM user AS u WHERE u.user_id=111

Enjoy !!! I hope it would be useful for you.

Page 1 of 41234