Friday, 13 May 2016

Data Structure & Algorithms


Data Structures are the programmatic way of storing data so that data can be used efficiently. Almost every enterprise application uses various types of data structures in one or other way.

Monday, 9 May 2016

Memcached Tutorial

Memcached is an open source, high-performance, distributed memory object caching system.

Memcached is an open source, high-performance, distributed memory caching system intended to speed up dynamic web applications by reducing the database load.

It is a key-value dictionary of strings, objects, etc, stored in the memory, resulting from database calls, API calls, or page rendering.

Memcached was developed by Brad Fitzpatrick for LiveJournal in 2003.

It is open source.

Memcached server is a big hash table.
(Hash Table is a data structure which store data in associative manner. In hash table, data is stored in array format where each data values has its own unique index value.)

It significantly reduces the database load.

It is perfectly efficient for websites with high database load.

It is a client-server application over TCP and/or UDP.

Memcached is not −
A persistent data store
(Persistent storage is any data storage device that retains data after power to that device is shut off. It is also sometimes referred to as non-volatile storage. )

A database

Application-specific

A large object cache

Fault-tolerant or

Highly available


Tuesday, 7 April 2015

Add Method in Jquery

<script>
$(document).ready(function(){
 
 $("#pop_report_form").validate({
 rules: {
hdn_select_any: {
 selectOne:true
}
},
 });
$.validator.addMethod("selectOne", function(value, element) {
var set_name = $('#set_name').val();
var player_name = $('#player_name').val();
if((player_name != '' && player_name != 'Player Name') || (set_name != '' && set_name != 'Set Name'))
{
return true; 
}
else
{
 return false;
}
}, function() {return 'Please Select Set or Player '});
});
</script>

Monday, 1 September 2014

Authenticate

    if (!isset($_SERVER['PHP_AUTH_USER'])) {
            header("WWW-Authenticate: Basic realm=\"Private Area\"");
            header("HTTP/1.0 401 Unauthorized");
            print "Please enter your username and password!\n";
            exit;
        } else {
            if (($_SERVER['PHP_AUTH_USER'] == 'modaym') && ($_SERVER['PHP_AUTH_PW'] == 'modaym123#')) {
               
            } else {
                header("WWW-Authenticate: Basic realm=\"Private Area\"");
                header("HTTP/1.0 401 Unauthorized");
                print "Please enter your username and password!\n";
                exit;
            }
        }

Friday, 24 January 2014

What's Stored Procedure

Stored Procedure is a Set precompiled Sql statements that used to Perform A special Task.
Stored Procedures are a batch of SQL statements that can be executed in a couple of ways.

A stored procedure, which calls itself, is recursive stored procedure. Almost RDMBS supports recursive stored procedure but MySQL does not support it well. Check your version of MySQL before using recursive stored procedure

• SP have repeatedly using data. It helps to reuse the code.
• SP is reduces the complexity of code in code behind.
• SP increase the security to application, it protect from Sql injection and hacking.
• Code maintenance and changes are done very easily. Instead of changing the code in code behind if changes required.

Wednesday, 22 January 2014

What is Locking in MySQL

Locking can be crucial to avoid two users modifying data at the same time. You may think that's unlikely, but depending on the application, there is a significant risk if the same data is frequently changed by different users.
Imagine the following situation without using locks: John opens his screen (he doesn't know he's using a database, he is only an end user who is looking at a pretty screen), modifies some data, and then hits "Save". Let's say John open the screen at 9:30 and then saves the data at 9:32.
However, Mary opened exactly the same screen and the same record at 9:29. She saw at that time the same data that John did at 9:30. Then, she updates the record, and hits "Save" at 9:31.
What data was saved? John's or Mary's?

Tuesday, 21 January 2014

MySQL Storage engines

A storage engine is a software which a DataBase management System uses to create, read, update and delete data from a database. - See more at: http://www.w3resource.com/mysql/mysql-storage-engines.php#sthash.Dyo7hV6k.dpuf
A storage engine is a software module that a DBMS uses to create, read, update and  delete (CRUD) data from a database. There are two types of storage engines in MySQL. Transactional and non-transactional.

The default storage engine for MySQL prior to version 5.5 was MyISAM. For MySQL 5.5 and later, the default storage engine is InnoDB. Choosing the right storage engine is an important strategic decision, which will impact future development. In this tutorial, we will be using MyISAM, InnoDB, Memory and CSV storage engines. If you are new to MySQL and your are studying the MySQL database management system, then this is not much of a concern. If you are planning a production database, then things become more complicated.

 

List of storage engines

MySQL supported storage engines:
  • MyISAM
  • InnoDB
  • Memory
  • CSV
  • Merge
  • Archive
  • Federated
  • Blackhole
  • Example

MyISAM is the original storage engine. It is a fast storage engine. It does not support transactions. MyISAM provides table-level locking. It is used most in Web, data warehousing.

InnoDB is the most widely used storage engine with transaction support. It is an ACID compliant storage engine. It supports row-level locking, crash recovery and multi-version concurrency control. It is the only engine which provides foreign key referential integrity constraint.

Memory storage engine creates tables in memory. It is the fastest engine. It provides table-level locking. It does not support transactions. Memory storage engine is ideal for creating temporary tables or quick lookups. The data is lost when the database is restarted.

CSV stores data in csv files. It provides great flexibility, because data in this format is easily integrated into other applications.

Merge operates on underlying MyISAM tables. Merge tables help manage large volumes of data more easily. It logically groups a series of identical MyISAM tables, and references them as one object. Good for data warehousing environments.

Archive storage engine is optimized for high speed inserting. It compresses data as it is inserted. It does not support transactions. It is ideal for storing, retrieving large amounts of seldom referenced historical, archived data.

The Blackhole storage engine accepts but does not store data. Retrievals always return an empty set. The functionality can be used in distributed database design where data is automatically replicated, but not stored locally. This storage engine can be used to perform performance tests or other testing.

Federated storage engine offers the ability to separate MySQL servers to create one logical database from many physical servers. Queries on the local server are automatically executed on the remote (federated) tables. No data is stored on the local tables. It is good for distributed environments.

Choosing the right engine

No storage engine is ideal for all circumstances. Some perform best under certain conditions and perform worse in other situations. There are tradeoffs than must be considered. A more secure solution takes more resources. It might be slower, take more CPU time and disk space. MySQL is very flexible in the fact that it provides several different storage engines. Some of them, like the Archive engine, are created to be used in specific situations. Ironically this also brings a question, which storage engine to use? Which may not be easily answered.
In some cases, the answer is clear. Whenever we are dealing with some payment systems, we are obliged to use the most secure solution. We cannot afford to loose such sensitive data. InnoDB is the way to go. If we want full-text search, than we must choose MyISAM. Only InnoDB supports foreign key referential integrity constraint and if we plan to use this constraint, then the choice is clear. In many situations we must have enough experience to choose the right engine. And if we lack the experience, than the best way is to ask some seasoned developer. One of the best ways is to ask on specific internet forums. stackoverflow.com is a great one. The question is further complicated by the fact, that we can choose different storage engines for different tables.

Specifying and altering storage engines

The storage engine is specified at the time of the table creation.
mysql> CREATE TABLE Cars(Id INTEGER PRIMARY KEY, Name VARCHAR(50), 
    -> Cost INTEGER) ENGINE='MyISAM';
The ENGINE keyword specifies the storage engine used for this particular table.
If we do not specify the storage engine explicitly, then the default storage engine is used. Prior to MySQL 5.5 the default storage engine was MyISAM. For MySQL 5.5 and later, the default storage engine is InnoDB.
mysql> SHOW VARIABLES LIKE 'storage_engine';
+----------------+--------+
| Variable_name  | Value  |
+----------------+--------+
| storage_engine | InnoDB |
+----------------+--------+
1 row in set (0.00 sec)
The default storage engine can be found in the storage_engine variable.
It is possible to migrate to a different storage engine. Note that migrating a large table might take a long time. Also we might run into some problems when migrating tables. Some features might not be supported in both tables.
mysql> SELECT ENGINE FROM information_schema.TABLES
    -> WHERE TABLE_SCHEMA='mydb'
    -> AND TABLE_NAME='Cars';
+--------+
| ENGINE |
+--------+
| InnoDB |
+--------+
1 row in set (0.00 sec)
This SQL statement finds out the storage engine used for a Cars table in mydb database. We could also use SELECT CREATE TABLE Cars SQL statement. The information_schema is a table which stores technical information about our tables.
mysql> ALTER TABLE Cars ENGINE='MyISAM';
This SQL statement changes the storage engine to MyISAM.
mysql> SELECT ENGINE FROM information_schema.TABLES
    -> WHERE TABLE_SCHEMA='mydb'
    -> AND TABLE_NAME='Cars';
+--------+
| ENGINE |
+--------+
| MyISAM |
+--------+
1 row in set (0.00 sec)
Now the storage engine is MyISAM.

Monday, 20 January 2014

How to Optimize a MySQL Database using phpMyAdmin



How to Optimize a MySQL Database using phpMyAdmin

  • Optimize Database
  • Repair Database
Optimize Table should be used if you have deleted a large part of a table or if you have made many changes to a table with variable length rows, such as VARCHAR, TEXT, BLOB or VARBINARY columns.  Deleted rows are maintained in the linked list and insert operations reuse the old row positions.  You can use "Optimize Table" to reclaim unused space and defragment the data file for optimal performance.  If a lot of changes have been made to a table, optimizing the table can sometimes significantly improve performance.

Step 1: Login to phpMyAdmin

cPanel: (Shared, Reseller, SEO, Linux Dedicated, VPS with cPanel)
  1. Login to cPanel
  2. Click on the phpMyAdmin button in the Databases section.
Plesk 10: (Windows Shared, Windows Dedicated, VPS with Plesk)
  1. Login to Plesk
  2. Click on the Websites & Domains tab.
  3. Click on the Databases icon.
  4. Click on the database you want to manage.
  5. Click on the Webadmin icon.

Step 2: Optimize Tables

  1. Select the database you want to optimize from the list in the left column, which should take you to the "structure" tab for the database.
  2. Select the tables you wish to optimize by checking the check box in front of each one, or clicking on Select All if you want to optimize all of them.
  3. On the drop down box that says "with selected..." select "Optimize Table."  This will optimize the table and take you to a new screen.

How to Repair a Broken Database

If you get the following error, it can easily be fixed from within cPanel:
cpaneluser_database is marked as crashed and needs to be repaired

Checking the Database

Even with different kinds of errors such as "supplied argument is not a valid" or "table attribute does not exist," the following steps can be used with this built-in cPanel test to try fixing the issue.
  1. Log into cPanel and navigate to the Databases section.
  2. Click on the MySQL Databases icon.
  3. Under Modify Databases, look for the drop-down menu called Check DB.
  4. Select the database name which is having trouble.
  5. Click the Check DB button.

Repairing the Database

The checking process should reveal the cause of the problem. If the problem is "marked as crashed," then proceed with the steps listed below:
  1. Go back to MySQL Databases.
  2. Under Modify Databases, look for the drop-down called Repair DB.
  3. Select the database name which is having trouble.
  4. Click the Repair DB button.
  5. Once complete, reload your web site.

Wednesday, 30 October 2013

No WWW Using .htaccess

There are some clear benefits to removing the "www" from your URLs:
  • Shorter URLs
  • Prevention of Google search engine penalties for duplicate content
  • Less bandwidth usage if you have many links per page
Luckily, removing the WWW from your page URLs (and subsequent Google listings) can be done inside your .htaccess file so that you wont have to go into every page on your website and remove the "www" from your anchors.

The .htaccess Code

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^domain.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [L,R=301]
 
Conversely, if you'd prefer to use "www" in all of your URLs, you can code:

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]
 
Save some URL characters and remove WWW from your site!

Friday, 6 September 2013

PHP compiler - HipHop

HipHop is a execution engines and improvements created by Facebook. 
HipHop was develop to save resources on Facebook servers. 
HipHop is currently around 1.9 million lines of mostly C++, C and PHP source code and is distributed as open source. 
It programmatically transforms your PHP source code into highly optimized C++ and then uses g++ to compile it.

Friday, 7 June 2013

Export CSV file in PHP

  header("Content-type:text/octect-stream");
  header("Content-Disposition:attachment;filename=data.csv");
 $recordlist = $this->db->query("SELECT * FROM `table` ");

        foreach($recordlist ->result_array() as $row)
        {
            print '"' . stripslashes(implode('","',$row)) . "\"\n";
        }
        exit;

How to enable gzip compression using cpanel

Login into cpanel  -> Software/Services -> Optimize Website -> Now Click on 'Compress all content'

Now check your site performance using this site
http://gtmetrix.com/















Monday, 22 April 2013

A WordPress blog in CakePhp site.

Create a folder blog in app->webroot in cakephp site.

Upload your wordpress blog in this folder.

Modify your root .htaccess  file in cakeph.

<IfModule mod_rewrite.c>
   RewriteEngine on
   RedirectMatch temp ^/blog/wp-admin$ site_name/blog/
    RewriteRule ^blog$ blog/ [L]
    RewriteRule ^blog/wp-admin$ blog/wp-admin/ [L]
   RewriteRule    ^$ app/webroot/    [L]
   RewriteRule    (.*) app/webroot/$1 [L]
</IfModule>

Now admin URL
site_name/blog/wp-login.php

Sunday, 26 February 2012

Cakephp interview questions

What is cakephp?
Cakephp is a rapid development framework for PHP that provides an extensible architecture for developing, maintaining, and deploying applications. it uses commonly known design patterns like MVC,ORM within the convention over configuration paradigm, It also reduces development costs and helps developers write less code.

Saturday, 25 February 2012

Top 10 PHP Frameworks

These are the top ten PHP frameworks that are based on the MVC design pattern.

1. Yii

Yii is a component-based high-performance PHP framework for developing large-scale Web applications. Yii is written in strict OOP and comes with thorough class reference and comprehensive tutorials. From MVC, DAO/ActiveRecord, widgets, caching, hierarchical RBAC, Web services, to theming, I18N and L10N, Yii provides nearly every feature needed by today’s Web 2.0 application development. And all these come without incurring much overhead. As a matter of fact, Yii is one of the most efficient PHP frameworks around.

Friday, 24 February 2012

Model View Controller(MVC) in PHP

MVC is a design pattern. A Design pattern is a code structure that allows for common coding frameworks to be replicated quickly.

The MVC paradigm is a way of breaking an application, or even just a piece of an application's interface, into three parts: the model, the view, and the controller. MVC was originally developed to map the traditional input, processing, output roles into the GUI realm:

Input --> Processing --> Output
Controller --> Model --> View

So what is a CMS ?

CMS Website Design (Content Management System)
CMS or a 'Content Management System' quite literally allows you to control and manage the content within your web site - without technical training. Using this uncomplicated system you can very easily add, delete images and edit text in your web site on the fly. You can also have an unlimited number of pages and a full site-search engine.