Friday, 29 July 2011

How to delete duplicate record in mysql?

Hi Folks,

Suppose we have a table name employee consisting two fields:

Table Name: employee
id  name
1   ashwani
2   varun
3   rajesh
4   varun
5   amit
6  ashwani

CREATE TABLE new_employee as SELECT * FROM employee WHERE 1 GROUP BY name;

DROP TABLE employee;

RENAME TABLE new_employee TO employee;


How to enable error log in php?

Hi Folks,

Go to vim etc/php5/apache2/php.ini where you will find log_errors = Off

change Off to On. save file and exit.

Now restart apache server with the following line:

sudo etc/init.d/apache2 restart


To see what is coming into log, do the following task:

create php file and wirte some code with errors.

and run the following command:
tail -f var/log/apache2/error.log


Wednesday, 20 July 2011

How to get 2nd highest salary in mysql?

HI Guys,

There are two way to get solution:

1.) select distinct(salary) from employee order by salary desc limit 1,1 ;
2.) select max(salary) from employee where salary < (select max(salary) from employee);



Monday, 18 July 2011

How to dump database using linux command?



host = localhost
user = root
password = root
database = payforme


Type the following command:
$ mkdir mysqldumpfolder;
$ cd mysqldumpfolder;
mysqldumpfolder $ mysqldump -u root  -h localhost -p  payforme | gzip -9 > payforme.sql.gz;

After enter it will ask you to enter password.
give mysql password and mysql start dumping your database to mysqldumpfolder folder.

Friday, 15 July 2011

How to get all form error in symfony?

Hi Guys,

1. First Method:

Add following line in the template:

foreach($form->getWidgetSchema()->getPositions() as $widgetName)
  echo $widgetName." == ".$form[$widgetName]->renderError();
  echo "<br />";

Using above script, you will find something like this:

first_name == Please enter First Name.
last_name == Please enter Last Name.
address1 == Please enter Address 1.

2. Second Method:

 public function getAllErrors()
       $err = array();
       foreach ($this as $form_field){
         if ($form_field->hasError()){
           $err_obj = $form_field->getError();
           if ($$err_obj instanceof sfValidatorErrorSchema){
             foreach ($err_obj->getErrors() as $err){
               $err[$form_field->getName()] = $err->getMessage();
             $err[$form_field->getName()] = $err_obj->getMessage();
       // global err
       foreach ($this->getGlobalErrors() as $validator_err){
         $err[] = $validator_err->getMessage();
       return $err;

put above function in your form class. and call this function in your action.class.php as given below:


Using above method, you will get something like this:

    [first_name] => Please enter First Name.
    [last_name] => Please enter Last Name.
    [address1] => Please enter Address 1.
    [town] => Please enter Town.
    [country] => Please select Country
    [email] => Please enter E-Mail address
    [phone] => Please enter Phone Number
    [address_proof] => Please upload credit card statement.
    [user_id_proof] => Please upload identity proof.
    [card_Num] => Please enter Card Number
    [card_holder] => Please enter Card Holder name.
    [transaction_type] => Please select transaction type.