Simple steps to set Master / Slave replication in MySQL Database
Why i have to do master-slave replication using MySQL?
1. One of the biggest advantages to have master-slave set up in MySQL is to be able to use master for all of the inserts, update and delete queries and slave for select queries. This will most probably speed up your application without having to diving into optimizing all the queries or buying more hardware.
2. Do backups from slave: One of the advantages people overlook is that you can use MySQL slave to do backups from. That way site is not affected at all when doing backups.
Goal: Master DB - Use db only for insert,delete and updated queries
Slave DB - Use db only for select queries
There are several Master-Slave replication available in MySQL. Below is the one of the best Master-Slave replication.
Note:
1. Below configuration is only for a single database replication.
2. Do the step 1 and step 2 in your master server and step 3 and step 4 slave servers.
3. Before doing all steps, you must create database and repective tables in your master and slave server.
Step 1: (Activate binary(bin) log in MySQL)
vi /etc/my.cnf
===============
log-bin = mysql-bin
binlog-do-db = databasename // give your database name
server-id = 1 // unique id depend upon your servers
Step 2: (Creating a new user in Master)
In mysql... login as root user.
Execute php codes in your WordPress Page without Plug-ins!
Below are the simple steps to create a WordPress Page with capability to execute php code without any wordpress plug-ins!
Step1 : Goto your theme directory and create a page template as follows in the screen shot!
Step 2: Save this file in your current theme directory.
Cross-domain communications with JSONP using JavaScript and jQuery!
Asynchronous JavaScript and XML (Ajax) is the key technology driving the new generation of Web sites, popularly termed as Web 2.0 sites.Ajax allows for data retrieval in the background without interfering with the display and behavior of the Web application. Data is retrieved using the XMLHttpRequest function, which is an API that lets client-side JavaScript make HTTP connections to remote servers.
This approach, however, does not allow cross-domain communication because of restrictions imposed by the browser. If you try to request data from a different domain, you will get a security error.
The same-origin policy limitations:
The same-origin policy prevents a script loaded from one domain from getting or manipulating properties of a document from another domain. That is, the domain of the requested URL must be the same as the domain of the current Web page.
How to resolve?
Technique 1:
One relatively simple way to overcome this limitation is to have the Web page request data from the Web server it originates from, and to have the Web server behave as a proxy relaying the request to the actual third-party servers. Although widely used, this technique isn’t scalable.
Technique 2:
Another way is to use frame elements to create new areas in the current Web page, and to fetch any third-party content using GET requests. After being fetched, however, the content in the frames would be subject to the same-origin policy limitations.
Technique 3 (Using JSONP):
A more promising way to overcome this limitation is to insert a dynamic script element in the Web page, one whose source is pointing to the service URL in the other domain and gets the data in the script itself. When the script loads, it executes.
It works because the same-origin policy doesn’t prevent dynamic script insertions and treats the scripts as if they were loaded from the domain that provided the Web page. But if this script tries to load a document from yet another domain, it will fail. Fortunately, you can improve this technique by adding JavaScript Object Notation (JSON) to the mix.
JSONP Using Javasript:
Your client-side code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<title>jsonp</title>
</head>
<body>
<span></span>
<script>
//this function is the callback, it needs to be a global variable
function readResponse(response){
document.getElementsByTagName('SPAN')[0].innerHTML = response.time + ' is from php file';
console.log(response);
}
(function(){
//note the "readResponse" at the end
var src = 'http://www.your-cross-domain.com/index.php?id=18&callback=readResponse',
script = document.createElement('SCRIPT');
script.src = src;
document.body.appendChild(script);
})();
</script>
</body>
</html>
Your server-side coding:
<?php
$array = array("time"=>time());
if($_GET['callback']){
header('Content-type: application/json');
echo $_GET['callback']."(".json_encode($array).")";
exit();
}
?>
JSONP using jQuery:
<!DOCTYPE html>
<html>
<head>
<style>img{ height: 100px; float: left; }</style>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<div id="images">
</div>
<script>
$.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?jsoncallback=?", {
tags: "cat",
tagmode: "any",
format: "json"
}, function (data) {
$.each(data.items, function (i, item) {
$("<img/>").attr("src", item.media.m).appendTo("#images");
if (i == 3) return false;
});
});
</script>
</body>
</html>
Need RSS feed parser for a wordpress site?
Importing and displaying external RSS feeds on your site is a great way to share your online activity with your visitors. If you are active on Flickr, Delicious, Twitter, or Tumblr, your visitors will enjoy staying current with your updates. Many social media sites provide exclusive feeds for user-generated content that may be imported and displayed on virtually any web page. In this article, you will learn three ways to import and display feed content on your WordPress-powered website — without installing yet another plugin.
What is magpie?
MagpieRSS is an XML-based (expat) RSS parser in PHP. WordPress uses Magpie to parse RSS and Atom feeds and display them on your website. Magpie parses feeds for two different WordPress functions.
- wp_rss() - fetches and parses feeds for instant
- fetch_rss() - fetches and parses feeds for advanced
Ref Site: Readmore
Show Password Text in Password Input Field
As you know, the user login box of the website contains the following fields username and password. Furthermore, most of them put the “Username” inside user name field and “********” inside password field to save the space within designing.In this post I’ll show you how to show “Password” text in the password field. It doesn’t actually does so but this tips will make it looks like so.
How it's done
The type of field cannot be changed with Javascript from type="text" to type="password" so there are actually two fields for the password: a regular password field, and a second plain text field with the default "Password" value.
When the page is loaded the CSS makes the plain text field hidden. Then the jQuery / js makes the password field hidden and the plain text field visible. It's best to do it this way so if Javascript is not enabled (or there's a Javascript error which causes the rest of the script to stop running) then the user still has a regular password field with obscured text.
When the user clicks the plain text field, the jQuery / JS code makes the plain text field hidden, the password field visible and puts focus on the password field. On blur, if the password field contains an empty value the plain text field is restored as the visible one to show the default value.
Download (Both jQuery type and js type)
Ajax PHP Flat Calendar – Customizable PHP based event Calendar
Are you looking for php based calendar script for your site?
Here is the download link for this calendar. Hope this will help for you!
Demo: AJAX PHP FLAT CALENDER
- Ajax based PHP Calendar - No page reloading and Flat type calendar.
- Simple in Coding - Used very basic php and ajax script
- Easy to customize for your web based php project.
- Completely free to download and free to modify this script.
- It works with PHP4 and PHP 5
Installation:
- Extract this folder to your server directory.
- Point out the directory(ajaxcalender) in your browser.
Important MySQL Questions and Answers
How many types of join are supported by mysql? Which are they? Explain:
ans: there are three types of joins supported in mysql as inner, right and left.
The inner join displays all the rows from both tables where match is found.
Left join returns all the rows from first table even if the match is not found in second table.
While the right join returns all the rows from second table even if match is not found in first table.
What are the advantages of mysql comparing with oracle?
MySql has many advantages in comparison to Oracle.
1 - MySql is Open source, which can be available any time
2 - MySql has no cost of development purpose.
3 - MySql has most of features , which oracle provides
4 - MySql day by day updating with new facilities.
5 - Good for small application.
6 - easy to learn and to become master.
7 - MySql has a good power these days.
even though MySql having so many advantages, Oracle is best database ever in Software development.
What are the limitations of mysql in Comparison of Oracle?
- Mysql supports six different types of tables, four of which do not support transactions (MyISAM, MERGE, ISAM, and HEAP)
- MySQL only supports one index type
- Unlike Oracle, MySQL date data types can store invalid dates, do not support time zones, and the precision of time values is limited to one second.
How many drivers in MYSQL?
There are eleven drivers in MYSQL .Six of them from MySQL AB and five by MYSQL Communities. They are1.PHP Driver2.ODBC Driver3.JDBC Driver4.ado.net5.mxj6.CAPI1PHP DRIVER2.PERL DRIVER3.PYTHON DRIVER4.RUBY DRIVER5.C++ WRAPPER
How are triggers created in MySQL?
CREATE TRIGGER `tgr_name` AFTER UPDATE ON `addresses` FOR EACH ROW begin
update products set countryName = new.countryName where products.shippingAddressId = old.id;
end;
Problem with transparent image resizing? – PHP
You will get black background if you resize a transparent image. To fix it, You need set alpha channel imagecolorallocatealpha to 127. With imagecolorallocatealpha, it will allocate a color for an image.
Usage:
int imagecolorallocatealpha ( resource image, int red, int green, int blue, int alpha)
From PHP manual:
imagecolorallocatealpha() behaves identically to imagecolorallocate() with the addition of the transparency parameter alpha which may have a value between 0 and 127. 0 indicates completely opaque while 127
indicates completely transparent. Returns FALSE if the allocation failed.
Before using it, you must set to false the blending mode for an image and set true the flag to save full alpha channel information.
Example:
<?
$newImg = imagecreatetruecolor($nWidth, $nHeight);
imagealphablending($newImg, false);
imagesavealpha($newImg,true);
$transparent = imagecolorallocatealpha($newImg, 255, 255, 255, 127);
imagefilledrectangle($newImg, 0, 0, $nWidth, $nHeight, $transparent);
imagecopyresampled($newImg, $im, 0, 0, 0, 0, $nWidth, $nHeight, $imgInfo[0], $imgInfo[1]);
?>
Another way to fix this issue:
phpThumb() - Resize images on the fly
Description: phpThumb() uses the GD library to create thumbnails from images (JPEG, PNG, GIF, BMP, etc) on the fly. The output size is configurable (can be larger or smaller than the source), and the source may be the entire image or only a portion of the original image.
Download: Download
Site: phpThumb()
Demo: Demo
Installation:
1. unzip the folder and upload the content into the server
2. give the correct path of the phpThumb.php and image path as per the following syntax
Resize Syntax:
<img src="../phpThumb.php?src=images/watermark.png&bg=FFFFFF&f=png" alt="">
<img src="../phpThumb.php?src=images/watermark.png&bg=FFFFFF&f=gif" alt="">
<img src="../phpThumb.php?src=images/watermark.png&bg=FFFFFF&f=jpeg" alt="">
where the bg=FFFFFF represents the bg color of your transparent image.
Media Box tools package using Mootools JS.
Media Box tools package using Mootools JS.
Ref: http://iaian7.com/webcode/Mediabox
Demo:open Yahoo Movies »
Download link: MediaBox Download link
I have created this package file for ready to access. This package contains following list of files
- index.php
- css/mediabox.css
- js/mediabox.js
- js/swfobject.js
- js/mootools.js
Installation:
- extract the zip file in to system.
- upload mediabox folder into your server.
- access the mediabox folder from the browser.
Using the MooTools 1.11 JavaScript library, Media box lets you open flash, video, and html content in a floating “lightbox” style window.
Mediabox will read Flickr, Google, MetaCafe, MySpace, Revver, YouTube, Veoh, Viddler, and Vimeo links by automatically translating them into embed code and inserting the video into the lightbox style effect.
Flash animation, flash video, QuickTime, windows media, inline content and external html content is all automatically recognised as well. Every link listed below is shown with the code used to make it.

