Tuesday, 28 January 2014

Call to undefined method DateTime::diff

Call to undefined method DateTime::diff

Lekhulal

lekhulal@gmail.com

----------------------------------------

Problem:-

$date1=new DateTime($row[0]); 

$date2=new DateTime(date("Y-m-d"));

$interval=$date1->diff($date2);

$a=$interval->days;

Fatal error: Call to undefined method DateTime::diff()

 

Solution:-

$date1 = strtotime($row[0]);

$date2 =strtotime(date("Y-m-d"));

$diff = $date2 - $date1;

$a = round($diff / 86400);

 

 

Friday, 24 January 2014

Delete all proceudres in a single query

 

 Delete all procedures in a single query

Lekhulal

lekhulal@gmail.com

----------------------------------------------------------------------------------------------------------------------------------------


DELETE FROM mysql.proc WHERE db = 'db_sample' AND type = 'PROCEDURE';

Friday, 3 January 2014

Combine both select statements into one select with different condition

Combine both select statements into one select with different condition
Lekhulal
lekulal@gmail.com 
----------------------------------------

Example:

The first query, with the only difference being the 
WHERE job_status=0



SELECT count(tbl_employer_post_details.employer_id) pending
FROM tbl_employer_post_details,tbl_employer_registration
WHERE job_status=0 
AND tbl_employer_registration.employer_id = 
    tbl_employer_post_details.employer_id;
 
The second query, with the only difference being the  
WHERE job_status=1
 
SELECT count(tbl_employer_post_details.employer_id) approved
FROM tbl_employer_post_details,tbl_employer_registration
WHERE job_status=1 
AND tbl_employer_registration.employer_id = 
    tbl_employer_post_details.employer_id;
 
Solution:
 
SELECT SUM(job_status = 0) pending, 
SUM(job_status = 1) approved 
FROM tbl_employer_post_details epd 
INNER JOIN tbl_employer_registration er  
ON epd.employer_id = er.employer_id
WHERE job_status IN (0, 1);
 
(OR)
 
SELECT SUM(job_status = 0) pending,
SUM(job_status = 1) approved
FROM tbl_employer_post_details d  
JOIN tbl_employer_registration r
ON r.employer_id = d.employer_id
WHERE job_status IN (0, 1)