How to run mysql query without cache?

Following query would be demonstrate how to run a MySQL query without Cache enable.

SELECT SQL_NO_CACHE id, name FROM customer;

Keep Querying ๐Ÿ™‚

Redirect request to other domain

I was trying to redirect all of my one wordpress blog setup which is setup on sub directory to the dedicated wordpress domain. To do so I have added following in directory based blog’s htaccess file:

RewriteEngine on

RewriteCond %{HTTP_HOST} ^example1.com$ [NC]
RewriteCond %{REQUEST_URI} ^/wp-blog/(.*) [NC]
RewriteRule ^(.*)$ http://example2-blog-site.com/%1

RewriteCond %{HTTP_HOST} ^www.example1.com$ [NC]
RewriteCond %{REQUEST_URI} ^/wp-blog/(.*) [NC]
RewriteRule ^(.*)$ http://www.example2-blog-site.com/%1

เชฎเชพเชฐเชฟ เชฎเชพ

เช•เซ‡เชฎ เช•เชฐเชฟเชจเซ‡ เชญเซเชฒเชพเชฏ เชคเชพเชฐเซ‹ เชชเซเชฐเซ‡เชฎ เชฎเชพเชฐเชฟ เชฎเชพ!
เช†เชœเซ‡ เชฎเชจเซ‡ เชชเชจ เชฎเชจเซ‡ เชฆเซ‡เช–เชพเชฏ เช›เซ‡ เช…เชถเซเชฐเซเช“ เชจเชพ เชฌเชฟเชจเซเชฆเซ เชคเชพเชฐเชฟ เช†เช–เซ‹ เชจเชพ เช•เชฟเชจเชพเชฐเซ‡ เชœเชฏเชพเชฐเซ‡ เช•เซ‹เช‡ เชฎเชจเซ‡ เชฆเซเช– เชฆเซ‡ เช›เซ‡.

เช•เซ‡เชฎ เช•เชฐเชฟเชจเซ‡ เชญเซเชฒเชพเชฏ เชคเชพเชฐเชฟ เชนเซเชฎเซเชซ เชฎเชพเชฐเชฟ เชฎเชพ!
เช†เชœเซ‡ เชชเชจ เชฎเชจเซ‡ เชฏเชพเชฆ เช†เชตเซ‡ เช›เซ‡ เชคเชพเชฐเชฟ เชธเชพเชกเชฟ เชจเซ‹ เชชเชพเชฒเชต เชฎเชพเชฐเซ€ เช—เชฎเซเช—เชฟเชจ เชฎเชพ.

เช•เซ‡เชฎ เช•เชฐเชฟเชจเซ‡ เชญเซเชฒเชพเชฏ เชคเชพเชฐเซ‹ เชธเชนเชพเชฐเซ‹ เชฎเชพเชฐเชฟ เชฎเชพ!
เช†เชœเซ‡ เชฎเชจเซ‡ เชชเชจ เชฎเชจเซ‡ เชœเชฐเซเชฐ เช›เซ‡ เชคเชพเชฐเซ‹ เช–เชญเซ‹(เชŸเซ‡เช•เซ‹) เช† เชธเซเชตเชพเชฐเซเชฅเชฟ เชฆเซเชจเชฟเชฏเชพ เชฎเชพ.

Types of fulltext search functions

I do remember my old days when I am new to MySQL and Web industry. At that point of time whenever I have to implement search functionality I was used to implement it via LIKE keyword as below:

SELECT * FROM tbl_name WHERE col_name LIKE “%search_term%”

At that time I am not aware of full-text search. When I explore through Full-Text search I laugh at myself just because of silly stuff I was doing. I found Full-Text search is much powerful, efficient, faster and accurate way to present results of search query.

To perform Full-Text search you need to define indexing on required columns.

There are few constrain to use Full-Text search:

  1. Full-Text index can be used by MyISAM storage engine only
  2. Full-Text index can be defined on CHAR, VARCHAR and TEXT datatype only.
  3. Full-Text index is an index type of FULLTEXT

Basic syntax ofย  full-text search function is:

MATCH(col1, col2, col3, ….) AGAINST (search_expr [search_modifier])

in above, MATCH takes comma separated column’s name and AGAINT takes string to be searched.

There are three different types of full-text searches available in MySQL

  1. Boolean Search
  2. Natural Language Search
  3. Query Expansion Search

Pages: 1 2

session lost between http and https

Today I came across strange problem. Let me explain you exact problem and solution for that.

Problem:

I have e-commerce site developed. After product added to shopping cart when user trying to checkout I am redirecting user from Shopping cart to Account page (if user already logged in) or Login Page (if user not logged in) on checkout. To make transaction more secure, Transition from shopping cart to Account page or Login Page is HTTP (Non-Secure) to HTTPS (Secure). Whenever I switch from HTTP to HTTPS, My stored shopping cart items which are stored in $_SESSION variable get lost.

Solution

After much hair pooling to trace and fix this issue I have found below solution:

When you switch between the HTTP and HTTPS services on the same server, your HTTP session ID is not being passed to the HTTPS session. Here we need to pass session_id which is created by HTTP to HTTPS page. so HTTPS resume similar session on server rather then creating new session for HTTPS request. Below is the code to explain it via example:

Consider you are redirectingย  http://www.example.com/page1.php toย  https://www.example.com/page2.php

page1.php script:

<?php
session_start();
$sess_id = session_id();
$_SESSION[‘someVar’] = “Var Value”;
echo “<a href=’https://www.example.com/page2.php?sess_id='&#8221;.$sess_id.”>Page2</a>”;
?>

page2.php script:

<?php
if(isset($_GET[‘sess_id’]) && $_GET[‘sess_id’]!=””)
{
session_id($_GET[‘sess_id’]);
}
session_start();

Hope above given solution help others as well.

Post comments if you have any question.

Happy Coding. ๐Ÿ™‚

Error Levels in PHP

Following error levels constants available into PHP for error_reporting which are configured directly from php.ini, .htaccess or directly from php script using ini_set function:

Value Constant Description
1 E_ERROR Fatal run-time errors. These indicate errors that can not be recovered from, such as a memory allocation problem. Execution of the script is halted.
2 E_WARNING Run-time warnings (non-fatal errors). Execution of the script is not halted.
4 E_PARSE Compile-time parse errors. Parse errors should only be generated by the parser.
8 E_NOTICE Run-time notices. Indicate that the script encountered something that could indicate an error, but could also happen in the normal course of running a script.
16 E_CORE_ERROR Fatal errors that occur during PHP’s initial startup. This is like an E_ERROR, except it is generated by the core of PHP.
32 E_CORE_WARNING Warnings (non-fatal errors) that occur during PHP’s initial startup. This is like an E_WARNING, except it is generated by the core of PHP.
64 E_COMPILE_ERROR Fatal compile-time errors. This is like an E_ERROR, except it is generated by the Zend Scripting Engine.
128 E_COMPILE_WARNING Compile-time warnings (non-fatal errors). This is like an E_WARNING, except it is generated by the Zend Scripting Engine.
256 E_USER_ERROR User-generated error message. This is like an
E_ERROR, except it is generated in PHP code by
using the PHP function trigger_error().
512 E_USER_WARNING User-generated warning message. This is like an E_WARNING, except it is generated in PHP code by using the PHP function trigger_error().
1024 E_USER_NOTICE User-generated notice message. This is like an
E_NOTICE, except it is generated in PHP code by
using the PHP function trigger_error().
2048 E_STRICT Enable to have PHP suggest changes to your code which will ensure the best interoperability and forward compatibility of your code.
4096 E_RECOVERABLE_ERROR Catchable fatal error. It indicates that a probably dangerous error occured, but did not leave the Engine in an unstable state. If the error is not caught by a user defined handle (see also set_error_handler()), the application aborts as it was an E_ERROR.
8192 E_DEPRECATED Run-time notices. Enable this to receive warnings about code that will not work in future versions.
16384 E_USER_DEPRECATED User-generated warning message. This is like an E_DEPRECATED, except it is generated in PHP code by using the PHP functiontrigger_error().
30719 E_ALL All errors and warnings, as supported, except of level E_STRICT in PHP < 6.

What is error_reporting & display_error?

There are little misunderstanding regarding two good configuration variablesย  available in php.ini.

  • error_reporting: This enables you to set error level i.e what are the different types of error you would like to log/show. All possible values for this setting are shown here
  • display_error: This enables you to show/hide errors on user browser if any error generated. Value for this setting will be on/off. Generally for development environment this should be on and for production environment this should be off due to security reason.

Both of the above settings are good for debugging and keep your application error free.

Happy Coding!

Post your comments if you have any question.

how to direct copy file/folder from server to server?

Following linux command use to copy file/folder from server to server:

scp [-o ssh_option ] [[user@ ] host1 : file1 ] [ ] [[user@ ] host2 : file2 ]

For Example:

scp -rv user@host:/path/to/source/dirORfile /path/to/destination

How to create virtualhosts on WAMP?

Let me explain virulhosts creation by taking example.ย  Lets say you want to create an virualhost for mylocalsite.com.

Follow as step below:

  1. Create a directory with name mylocalsite in your WAMP root folder.
    i.e: c:\wamp\www\mylocalsite
  2. Now create a logs directory into it.
    i.e: c:\wamp\www\mylocalsite\logs
  3. Use Notepad (or your desire text editor) to open file httpd.conf in folder C:\wamp\bin\apache\Apache2.2.11\conf and find these lines:
    #Include conf/extra/httpd-vhosts.conf

    and uncomment it as below(i.e remove # in front of line)

    Include conf/extra/httpd-vhosts.conf
  4. Now openย  C:\wamp\bin\apache\Apache2.2.11\conf\extra\httpd-vhosts.conf
    in notebook. And add following code into it:

    NameVirtualHost *:80
    <VirtualHost *:80>
    ServerName http://www.mylocalsite.com
    ServerAlias mylocalsite.com mylocalsite http://www.mylocalsite.com
    DocumentRoot C:/wamp/www/mylocalsite/
    ErrorLog C:/wamp/www/mylocalsite/logs/error.log
    CustomLog C:/wamp/www/mylocalsite/logs/access.log common
    </VirtualHost>

    <VirtualHost *:80>ServerName localhost
    DocumentRoot C:/wamp/www
    ErrorLog C:/wamp/www/logs/error.log
    CustomLog C:/wamp/www/logs/access.log common
    </VirtualHost>

  5. Now open your host file. It is located at C:\windows\system32\drivers\etc. Add following line at the bottom of the file.
    127.0.0.1ย ย ย ย ย ย  localhost
    127.0.0.1ย ย  ย www.mylocalsite.com
  6. Now restart wamp to take effect.
  7. Now enter http://www.mylocalsite.com or mylocalsite.com or mylocalsite in your browser URL and see the magic.

Drop me comment if you have any problem. I will surely help you.