Mysql Important

November 3, 2015 Leave a comment


#Login to mysql
mysql> -hlocalhost -P3306 -u{user name} -p

#Export database or table
mysql bin folder>mysqldump -hlocalhost -P3306 -u{username} -p{password} {database name} {table name} > export file path/filename.sqlpath/filename.sql

#Import database or table
mysql bin folder>mysql -hlocalhost -P3306 -u{username} -p{password} {database name} {table name} < import file path/filename.sql

Create: mysql>create view {view name} as select * from {table name};
View: mysql>show full tables;
mysql>show full tables in {database name} table_type like ‘view’;
Drop: mysql>drop view {view name};

mysql>delimiter //
mysql> create trigger {trigger name}
after insert
on {table name} for each row
insert into {table name} values(”, new. {new value});
mysql>delimiter ;

mysql>show triggers;

mysql>drop trigger {trigger name};

mysql>delimiter //
mysql>create procedure {procedure name}(in inputvalue int, out outputvalue int)
outputvalue = inputvalue;
end; //
mysql>delimiter ;

mysql>call {procedure name}(inputvalue, @output);
mysql>select @output;(result 100);

mysql>show procedure status;

mysql>drop procedure {procedure name};

mysql>delimiter //
mysql>create function {function name}({parameter name} {data type})
returns {data type}
declare {variable name} {data type};
select {variable name} into {paramerter name} from {table name} where id={parameter name};
return ({variable name});
end; //
mysql>delimiter ;


Categories: Mysql Tags: , , , , ,

Speed up site with .htaccess

January 20, 2015 1 comment

Append these line in your .htaccess file.

#Trun on compression

mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file \.(html?|txt|css|js|php)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*

#Turn on content caching

ExpiresActive On
ExpiresByType image/jpg “access plus 1 month”
ExpiresByType image/jpeg “access plus 1 month”
ExpiresByType image/gif “access plus 1 month”
ExpiresByType image/png “access plus 1 month”
ExpiresByType text/css “access plus 1 month”
ExpiresByType application/pdf “access plus 1 month”
ExpiresByType text/x-javascript “access plus 1 month”
ExpiresByType text/javascript “access plus 1 month”
ExpiresByType application/javascript “access plus 1 month”
ExpiresByType application/x-shockwave-flash “access plus 1 month”
ExpiresByType image/x-icon “access plus 1 month”

ExpiresByType application/font-woff “access plus 1 month”
ExpiresByType application/ “access plus 1 month”
ExpiresByType application/x-font-ttf “access plus 1 month”
ExpiresByType font/opentype “access plus 1 month”
ExpiresByType image/svg+xml “access plus 1 month”

ExpiresDefault “access 2 days”
Header set Cache-Control “public”
Header unset Cache-control

Header append Vary: Accept-Encoding
Header unset Pragma

#Mod_deflate is an apache module that can be used to compress data using gzip compression before sending it to the browser

AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/atom_xml
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/x-httpd-php
AddOutputFilterByType DEFLATE application/x-httpd-fastphp
AddOutputFilterByType DEFLATE application/x-httpd-eruby
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE application/x-font-ttf

Install Ruby On Windows

January 19, 2015 Leave a comment

Get ruby installer for windows from here
Download Development kit from here

Setup development enviorment-
1. Run ruby installer
a. Set installation path. Mine is C:\wamp\bin (I’m using wamp server for php and I’m going to use it’s mysql and Apache.)
2. Run Development kit installer
a. Set installation path. Mine is C:\wamp\bin\Ruby193\DevKit
3. Open commant prompet and run this command to check ruby version.
> ruby -v
OUtput comes like this ruby 1.9.3p551 (2014-11-13) [i386-mingw32] if not then set enviorment valiable for ruby. Mine is C:\wamp\bin\Ruby193\bin


December 20, 2014 Leave a comment

OPcache is bundled with PHP 5.5.0 and later, and is available in PECL for lower PHP version.
OPcache improves PHP performance. OPcache stores precompiled script bytecode in shared memory on first request. When next request comes then PHP does not compile that script, it uses precompiled script from OPcache.
cache opcache_reset() OPcache offers a function to reset.
pcache_invalidate ( string $script [, boolean $force = FALSE ] ) This function invalidate a script.

Enable OPcache on linux: To enable OPcache on linux uncommment or add this line in php.ini if this not enable OPcache on server then put full path of

OPcache configuration: You can change OPcache configuration from php.ini. Some important configuration setting are
1. opcache.revalidate_freq=60
Here 60 is seconds. OPcache validate cache after given seconds.

2. opcache.max_accelerated_files=7000
This is number of script sotre in OPcache. You can change this number as you needed.

To see OPcache configuratin and status you need a script on same server. Opcache-gui is the good script.

Scaling PHP Book

Categories: php Tags: , , , , , , ,

Install PhpUnit

March 7, 2014 1 comment

Run the Windows Command Processor (cmd.exe).
Run >pear channel-discover
Run >pear remote-list -c phpunit
You will see a similar screen:
DbUnit 1.3.0
Diff 1.1.0
Exporter 1.0.0
File_Iterator 1.3.4
FinderFacade 1.1.0
Git 1.2.0
PHPUnit 4.0.1
PHPUnit_MockObject 1.2.3
PHPUnit_Selenium 1.3.3
PHPUnit_SkeletonGenerator 1.2.1
PHPUnit_Story 1.0.2
PHPUnit_TestListener_DBUS 1.0.0
PHPUnit_TestListener_XHProf 1.0.0
PHPUnit_TicketListener_Fogbugz 1.0.0
PHPUnit_TicketListener_GitHub 1.0.0
PHPUnit_TicketListener_GoogleCode 1.0.0
PHPUnit_TicketListener_Trac 1.0.0
PHP_CodeBrowser 1.0.2
PHP_CodeCoverage 1.2.16
PHP_Invoker 1.1.3
PHP_Timer 1.0.5
PHP_TokenStream 1.2.2
Text_Template 1.2.0
Version 1.0.2
bytekit 1.1.3
phpcov 1.1.0
phpcpd 2.0.0
phpdcd -n/a-
phploc 2.0.4
test_helpers 1.1.0
Run >pear install phpunit/PHPUnit-4.0.1
You will see a similar screen:
downloading PHPUnit-4.0.1.tgz …
Starting to download PHPUnit-4.0.1.tgz (510,701 bytes)
….done: 510,701 bytes
install ok: channel://

Install PHP Mess Detector

March 7, 2014 1 comment

Run the Windows Command Processor (cmd.exe).
Run >pear channel-discover
Run >pear channel-discover
Run >pear install phpmd/PHP_PMD-1.5.0. You will see a similar screen:

Did not download optional dependencies: pecl/imagick, use –alldeps to download
pdepend/PHP_Depend can optionally use package “pecl/imagick” (version >= 2.2.0b2
downloading PHP_PMD-1.5.0.tgz …
Starting to download PHP_PMD-1.5.0.tgz (49,534 bytes)
………….done: 49,534 bytes
downloading PHP_Depend-1.1.4.tgz …
Starting to download PHP_Depend-1.1.4.tgz (179,584 bytes)
…done: 179,584 bytes
install ok: channel://
install ok: channel://

Install PEAR on windows

February 28, 2014 Leave a comment

Follow these steps-

  1. Get the file on the link ->
  2. Go to this directory C:\wamp\bin\php\php5.3.13. Put go-pear.phar her.
  3. Open command prompt (cmd.exe). Supposing you’re using Windows, press Start, type “cmd.exe” and right click on it and select run as administrator.
  4. Type this cd “C:\wamp\bin\php\php5.3.13” Press Enter. You should note that instead of saying “C:\system\32” is now displaying C:\wamp\bin\php\php5.3.13
  5. Write the following command and press Enter: php -d phar.require_hash=0 go-pear.phar
  6. Select whether you like or not a local copy or a system one. By typing system:local and pressing enter you’ll install a local copy. By typing system and pressing enter you’ll install a system-wide copy.
  7. Type yes to confirm the option chosen. The next list of directories, will be the referring directories that PEAR will install its components. If you select from 1 – 12 you can change the directory you’d like to install.

Get every new post delivered to your Inbox.

%d bloggers like this: