Sunday, March 5, 2017

htaccess Basics

ErrorDocument 404 http://fccollc.com/only-detail/7/index.php
ErrorDocument 500 http://fccollc.com/only-detail/7/index.php
IndexIgnore *      # prevent directory file liting in all folders


RewriteEngine on

RewriteBase /


#Options +FollowSymlinks
#RewriteEngine off


RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#######Remove Php Extension#############
RewriteCond %{REQUEST_FILENAME}\.php -f

RewriteRule ^Product/(.*)/(.*) product-detail.php?product_name=$1&id=$2
#RewriteRule Merchantdetail/(.*)/(.*)/(.*) merchantdetail.php?merchant_name=$1&area_name=$2&merchant_type=$3

RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ http://fccollc.com/fokkat/2/admin/$1/ [R=301,L]

RewriteRule ^(.*)$ index.php?/$1 [L]

RewriteCond %{HTTP_HOST} ^isess.in [NC]
RewriteRule ^(.*)$ http://www.isess.in/$1 [L,R=301]

Friday, March 3, 2017

Reading XLSX, ODS and text/CSV file

We can easily read these files using PHP spreadsheet reader. At first download PHP spreadsheet reader from spreadsheet-reader. you can also get sample code there.
 example for reading .xls file-

<?php

header('Content-Type: text/plain');
$Filepath = 'test.xlsx';
require('php-excel-reader/excel_reader2.php');
require('SpreadsheetReader.php');
try
{
$Spreadsheet = new SpreadsheetReader($Filepath);
/* for reading only first sheet */
/*
   foreach ($Spreadsheet as $Row)
   {
       print_r($Row);
   }*/
   /* for reading all first sheet or reading specific sheet */
$Sheets = $Spreadsheet -> Sheets();
foreach ($Sheets as $Index => $Name)
{
echo '*** Sheet '.$Name.' ***'.PHP_EOL;
$Spreadsheet -> ChangeSheet($Index);
foreach ($Spreadsheet as $Key => $Row)
{
echo $Key.': ';
if ($Row)
{
print_r($Row);
}
else
{
var_dump($Row);
}
}
echo '*** End of sheet '.$Name.' ***'.PHP_EOL;
}

}
catch (Exception $E)
{
echo $E -> getMessage();
}

?>

Thursday, March 2, 2017

Triger in sql

In simplicity Trigger's are used to perform some database operation if any defined event occurs on a specific table. Trigger call on Insert, Update and delete operation on before/after these event completed. To grab data we have to keyword new and old.
INSERT: new
UPDATE: new/old
DELETE: old

Syntax for creating trigger:
CREATE TRIGGER triger_name
BEFORE | AFTER event ON table_name
BEGIN
...
END;


example:

DELIMITER $$
CREATE TRIGGER updatedata
    AFTER UPDATE ON employees
    FOR EACH ROW
BEGIN
    UPADTE history
    SET old_sal=old.sal where emp_id=old.emp_id;
END$$
DELIMITER ;

DELIMITER $$
CREATE TRIGGER name_add
    BEFORE UPDATE ON employees
    FOR EACH ROW
BEGIN
    SET new.name=concat(new.salut,' ',new.fname,' ',new.lname);
END$$
DELIMITER ;

mysql> delimiter //
mysql> CREATE TRIGGER upd_check BEFORE UPDATE ON account
    -> FOR EACH ROW
    -> BEGIN
    ->     IF NEW.amount < 0 THEN
    ->         SET NEW.amount = 0;
    ->     ELSEIF NEW.amount > 100 THEN
    ->         SET NEW.amount = 100;
    ->     END IF;
    -> END;//
mysql> delimiter ;


sql to see all triggers : SHOW TRIGGERS;
sql to drop trigger: DROP TRIGGER trigger_name;