Difference between WHERE and HAVING

What is the difference between where clause and having clause?
The difference is that WHERE operates on individual rows, while HAVING operates on groups.
You can have WHERE without HAVING, you can have HAVING without WHERE, you can have both WHERE and HAVING, and you can have neither WHERE nor HAVING. But you can’t have HAVING without grouping, even if the group consists of the entire result set.

Posted in Mysql | Leave a comment

What is Normalization ?

Normalization is a formal approach that applies a set of rules to associate attributes with entities.

1) Normalization is the Logical Data Base Design.
2) It’s Used to Split the One table to multiple Table.
3) It’s used to Reduce the Redundancy of data.
4)Database normalization is a process in which data in a single table is being replaced into number of tables with the same data along with some key relationships being set up among the tables.
5)Step-by-step breakdown of complex data structure into simple ones without loss of any information and relationship.
6)Database normalization is a technique for designing
relational database tables to minimize duplication of
information and, in so doing, to safeguard the database
against certain types of logical or structural problems,
namely data anomalies.

When you normalize your data model, you can achieve the following goals. You can:

* Produce greater flexibility in your design.
* Ensure that attributes are placed in the proper tables.
* Reduce data redundancy.
* Increase programmer effectiveness.
* Lower application maintenance costs.
* Maximize stability of the data structure.

Posted in Mysql, Normalization, Uncategorized | Leave a comment

when and why use Interfaces in php

PHP Interfaces: when and why you should use them

First, what are interfaces?

* Interfaces are 100% abstract classes – they have methods but the methods have no ‘guts’.
* Interfaces cannot be instantiated – they are a construct in OOP that allows you to inject ‘qualities’ into classes .. like abstract classes.
* Where an abstract class can have both empty and working/concrete methods, interface methods must all be shells – that is to say, it must be left to the class (using the interface) to flesh out the methods.


Remember:
when a class uses/implements an interface, the class MUST define all the methods/functions of the interface otherwise the php engine will barf … ‘barf’ is a technical term for: give you an error.

PRIMARY PURPOSES OF AN INTERFACE:

* Interfaces allow you to define/create a common structure for your classes – to set a standard for objects.
* Interfaces solves the problem of single inheritance – they allow you to inject ‘qualities’ from multiple sources.
* Interfaces provide a flexible base/root structure that you don’t get with classes.
* Interfaces are great when you have multiple coders working on a project – you can set up a loose structure for programmers to follow and let them worry about the details.

WHEN SHOULD YOU MAKE A CLASS AND WHEN SHOULD YOU MAKE AN INTEFACE?

* If you have a class that is never directly instantiated in your program, this is a good candidate for an interface. In other words, if you are creating a class to only serve as the parent to other classes, it should probably be made into an interface.
* When you know what methods a class should have but you are not sure what the details will be.
* When you want to quickly map out the basic structures of your classes to serve as a template for others to follow – keeps the code-base predictable and consistent.

For more details:-
visit: http://www.killerphp.com/articles/php-interfaces/

Posted in PHP interview questions and answers | Leave a comment

Create XML Using database

$query = “SELECT * FROM craigslist_posting where status=’1′”;
$result = mysql_query($query);
$num = mysql_num_rows($result);
if($num){
$somecontent = ‘< ?xml version="1.0" encoding="utf-8"? >< urlstore >‘;
while($data = mysql_fetch_array($result))
{

$market_name = $data['market_name'];
$leadId = $data['listing'];
$craigslist = $data['craigslist'];
$imgName = trim($leadId).’_’.$data['craigslist'];
$FlyerUrl = URL.$market_name.’/’.$leadId.’/craigslist’.$craigslist.’.html’;

$somecontent .= “-”;
$somecontent .= “< url >“;
$somecontent .= “< id >$imgName< /id >“;
$somecontent .= “< link >$FlyerUrl< /link >“;
$somecontent .= “-”;
$somecontent .= “< footertext >“;
$somecontent .= ““;
$somecontent .= ““;
$somecontent .= ““;
$somecontent .= ““;
$somecontent .= “< /footertext >“;
$somecontent .= “< /url >“;
}
$somecontent .= ‘< /urlstore >‘;

/////////////////////////////////write data in file ////////////////////
$filename1 = “craigslist.xml”;
$filename = ‘/home/homesbyl/public_html/craigslist_files/’.$filename1;

if (!$handle = fopen($filename, ‘w’)) {
echo “Cannot open file ($filename)”;
exit;
}

if (fwrite($handle, $somecontent) === FALSE) {
echo “Cannot write to file ($filename)”;
exit;
}
fclose($handle);

//////////////////////////////////////////// end///////////////////////
}

Posted in PHP | Leave a comment

Create a random password

Create a random password using rand() function with length 7 characters

function createRandomPassword() {

$chars = “abcdefghijkmnopqrstuvwxyz023456789!@#$%^&*”;
srand((double)microtime()*1000000);
$i = 0;
$pass = ” ;
while ($i <= 7) {
$num = rand() % 33;
$tmp = substr($chars, $num, 1);
$pass = $pass . $tmp;
$i++;
}

return $pass;
}
// Usage
$password = createRandomPassword();
echo “Your random password is: $password”;

Posted in PHP | Leave a comment

Disabling right click

Disabling right click using javascript

//Disable right mouse click Script
//By Maximus (maximus@nsimail.com) w/ mods by DynamicDrive
//For full source code, visit http://www.dynamicdrive.com

var message=”Function Disabled!”;

///////////////////////////////////
function clickIE4(){
if (event.button==2){
alert(message);
return false;
}
}
function clickNS4(e){
if (document.layers||document.getElementById&&!document.all){
if (e.which==2||e.which==3){
alert(message);
return false;
}
}
}

if (document.layers){
document.captureEvents(Event.MOUSEDOWN);
document.onmousedown=clickNS4;
}
else if (document.all&&!document.getElementById){
document.onmousedown=clickIE4;
}

document.oncontextmenu=new Function(“alert(message);return false”)

Posted in JavaScript | Leave a comment

How PHP program execute

System program execution

Introduction
Those functions provide means to execute commands on the system itself, and means to secure such commands.
Note:
All execution functions call the commands through cmd.exe under Windows. Therefore the user calling these functions needs appropriate privilege to run this command. The only exception is proc_open() with bypass_shell option.

Program execution Functions

See Also

These functions are also closely related to the backtick operator. Also, while in safe mode you must consider the safe_mode_exec_dir directive.
Table of Contents

* escapeshellarg — Escape a string to be used as a shell argument
* escapeshellcmd — Escape shell metacharacters
* exec — Execute an external program
* passthru — Execute an external program and display raw output
* proc_close — Close a process opened by proc_open and return the exit code of that process
* proc_get_status — Get information about a process opened by proc_open
* proc_nice — Change the priority of the current process
* proc_open — Execute a command and open file pointers for input/output
* proc_terminate — Kills a process opened by proc_open
* shell_exec — Execute command via shell and return the complete output as a string
* system — Execute an external program and display the output

Within Linux, when calling the php interpreter directly from popen, or other program execution function to execute a script, it appears as though the script perpetually fails and re-executes.

i.e.

As each re-execution causes the executing script to load under a new PID, it is incredibly difficult to identify and kill the process manually.

[One solution is] to ensure the executing script has a valid shebang, and execute permissions. This allows you to execute the script directly

i.e.

For More Details Visit :- http://in2.php.net/manual/en/book.exec.php

Posted in PHP | 1 Comment

Find Image Size

Get Image Size
1) array getimagesize ( string $filename [, array &$imageinfo ] )
The getimagesize() function will determine the size of any given image file and return the dimensions along with the file type and a height/width text string to be used inside a normal HTML tag and the correspondant HTTP content type.

getimagesize() can also return some more information in imageinfo parameter.

$size = getimagesize(“http://www.example.com/gifs/logo.gif”);

2) int imagesx ( resource $image )
Returns the width of the given image resource.
$img = imagecreatetruecolor(300, 200);

echo imagesx($img); // 300

3) int imagesy ( resource $image )
Returns the height of the given image resource.
$img = imagecreatetruecolor(300, 200);

echo imagesy($img); // 200

Thanks
Sanjeev

Posted in PHP | Leave a comment

Change imagesize

1) Find Image size Using getimagesize()
$size = getimagesize(“http://www.example.com/gifs/logo.gif”);
2) If Image Size is grater then required size then put required image size.
3) Also you can set no_image image if no image exist.
$path_parts = “”;
$path_parts = getimagesize(DIR_WS_IMAGES . $best_sellers['products_image']);
$height = “”;
$weight = “”;
if($path_parts[0] > ’140′){
//$height =55;
$weight = 140;
}
$listingProducts_image = “”;
if($best_sellers['products_image']==”" || $best_sellers['products_image']==”NULL”){
$listingProducts_image = “No_Image_Available.gif”;
}else{
$listingProducts_image = $best_sellers['products_image'];
}

Thanks
Sanjeev

Posted in PHP | Leave a comment

Install zend framwork on Localhost

1) Go to php.ini
2) Find include_path
3) Add semicolon on existing path like
include_path = “\path1;\path2″
include_path = “.;D:\xampp\php\pear\” This is existing path
4) Now you need to add “C:\Program Files\Zend\ZendFramework-1.0.1\library”
Finely it become:-

include_path = “.;D:\xampp\php\pear\; C:\Program Files\Zend\ZendFramework-1.0.1\library”

Thanks
Sanjeev Lahariya

Posted in PHP, Zend Framwork | Leave a comment