Tuesday 4 August 2015

Improve MySQL Query Performance Tips

Improve MySQL Query Performance Tips



I am sharing some of my understanding on how to improve any MySQL Query performance, as per me below points makes the queries faster. May these points helpful for someone.





Tips
  1. Make index of columns used in where clause but not many columns, only higher priority columns.
  2. Always make joins on int columns.
  3. Use subquery or IN statement in place of joins.
  4. Don't select * from [table], always provide specific select columns in a query.
  5. Use Group By in place of DISTINCT.
  6. Use UTF-8 general collation for tables and columns.
  7. Some INNODB Engine tables configurations are helpful at server level. Below link can be helpful:
               MySQL Performance Tips

Get Random Values From Array IN PHP

Get Random Values From Array IN PHP



I am sharing my example code to get random values from PHP array. May this small code can be helpful for someone.





<?php

// array
$arr_subjects = array('Science', 'Maths', 'GK', 'Law', 'History', 'Arts', 'Chemistry',
    'Computers', 'Bio', 'Music');
// random number
$c = rand(1, 6);
//shuffle array elements
shuffle($arr_subjects);

//print random values in an array
print_r(array_slice($arr_subjects, $c, $c));
// prints $c'th elements from $c'th position in an array

Create .ICS file using PHP code

Recently worked on creating a .ics file in PHP after a very long time, code so thought to share with everybody. Please find below the comple...