This is default featured post 1 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured post 2 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured post 3 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured post 4 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured post 5 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

Wednesday 15 July 2015

SQL - JOIN in SQL Server

SQL join clause combines records from two or more tables in a relational database. It creates a set that can be saved as a table or used as it is. A JOIN is a means for combining fields from two tables (or more) by using values common to each.




Different SQL JOINs

  • INNER JOIN: Returns all rows when there is at least one match in BOTH tables
  • LEFT JOIN: Return all rows from the left table, and the matched rows from the right table
  • RIGHT JOIN: Return all rows from the right table, and the matched rows from the left table
  • FULL JOIN: Return all rows when there is a match in ONE of the tables

Types of SQL Joins

As we said above, a SQL join is a instruction to a database to combine data from more than one table. There are different kinds of joins, which have different rules for the results they create.
Let's look at the different kinds of SQL joins:
Inner Join
An inner join produces a result set that is limited to the rows where there is a match in both tables for what we're looking for.  If you don't know which kind of join you need, this will usually be your best bet.

Example:
SELECT gid, first_name, last_name, pid, gardener_id, plant_name 
FROM Gardners
INNER JOIN Plantings
ON gid = gardener_id

Left Outer Join

A left outer join, or left join, results in a set where all of the rows from the first, or left hand side, table are preserved. The rows from the second, or right hand side table only show up if they have a match with the rows from the first table.  Where there are values from the left table but not from the right, the table will read null, which means that the value has not been set.
Example:
SELECT gid, first_name, last_name, pid, gardener_id, plant_name 
FROM Gardners
LEFT OUTER JOIN Plantings
ON gid = gardener_id     

Right Outer Join

A right outer join, or right join, is the same as a left join, except the roles are reversed.  All of the rows from the right hand side table show up in the result, but the rows from the table on the left are only there if they match the table on the right.  Empty spaces are null, just like with the the left join.
Example:
SELECT gid, first_name, last_name, pid, gardener_id, plant_name 
FROM Gardners
RIGHT OUTER JOIN Plantings
ON gid = gardener_id    

Full Outer Join

A full outer join, or just outer join, produces a result set with  all of the rows of both tables, regardless of whether there are any matches.  Similarly to the left and right joins, we call the empty spaces null.
Example
SELECT gid, first_name, last_name, pid, gardener_id, plant_name 
FROM Gardners
FULL OUTER JOIN Plantings
ON gid = gardener_id    

Cross Join

The cross join returns a table with a potentially very large number of rows.  The row count of the result is equal to the number of rows in the first table  times the number of rows in the second table. Each row is a combination of the rows of the first and second table.
Example:
SELECT gid, first_name, last_name, pid, gardener_id, plant_name 
FROM Gardners
CROSS JOIN Plantings

Self Join

You can join a single table to itself.  In this case, you are using the same table twice.
Example:
SELECT G1.gid, G1.first_name, G1.last_name, G2.gid, G2.first_name, G2.last_name
FROM Gardners G1
INNER JOIN Gardners G2 
ON G1.first_name = G2.first_name

Sunday 2 February 2014

Step to Send email from localhost/WAMP Server

This solution requires sendmail.exe (a Command Line Interface (CLI) executable which accepts email from PHP, connects to an SMTP server and sends email). You will not require to use it by command, don’t bother about it :-) Download the sendmail.zip and follow these steps:
  • Create a folder named “sendmail” in “C:\wamp\”.
  • Extract these 4 files in “sendmail” folder: “sendmail.exe”, “libeay32.dll”, “ssleay32.dll” and “sendmail.ini”.
  • Open the “sendmail.ini” file and configure it as following
    • smtp_server=smtp.gmail.com
    • smtp_port=465
    • smtp_ssl=ssl
    • default_domain=localhost
    • error_logfile=error.log
    • debug_logfile=debug.log
    • auth_username=[your_gmail_account_username]@gmail.com
    • auth_password=[your_gmail_account_password]
    • pop3_server=
    • pop3_username=
    • pop3_password=
    • force_sender=
    • force_recipient=
    • hostname=localhost
    You do not need to specify any value for these properties: pop3_server, pop3_username, pop3_password, force_sender, force_recipient. The error_logfile and debug_logfile settings should be kept blank if you have already sent successful email(s) otherwise size of this file will keep increasing. Enable these log file settings if you don’t get able to send email using sendmail.
  • Enable IMAP Access in your GMail’s Settings -> Forwarding and POP/IMAP -> IMAP Access:
  • Enable “ssl_module” module in Apache server:
  • Enable “php_openssl” and “php_sockets” extensions for PHP compiler:
  • Open php.ini from “C:\wamp\bin\apache\Apache2.2.17\bin” and configure it as following (The php.ini at “C:\wamp\bin\php\php5.3.x” would not work) (You just need to configure the last line in the following code, prefix semicolon (;) against other lines):
    [mail function]
    ; For Win32 only.
    ; http://php.net/smtp
    ;SMTP = 
    ; http://php.net/smtp-port
    ;smtp_port = 25
    
    ; For Win32 only.
    ; http://php.net/sendmail-from
    ;sendmail_from = you@domain.com
    
    ; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
    ; http://php.net/sendmail-path
    sendmail_path = "C:\wamp\sendmail\sendmail.exe -t -i"
  • Restart WAMP Server.
  • Create a PHP file and write the following code in it:
    <?php
    $to       = 'recipient@yahoo.com';
    $subject  = 'Testing sendmail.exe';
    $message  = 'Hi, you just received an email using sendmail!';
    $headers  = 'From: sender@gmail.com' . "\r\n" .
                'Reply-To: sender@gmail.com' . "\r\n" .
                'MIME-Version: 1.0' . "\r\n" .
                'Content-type: text/html; charset=iso-8859-1' . "\r\n" .
                'X-Mailer: PHP/' . phpversion();
    if(mail($to, $subject, $message, $headers))
        echo "Email sent";
    else
        echo "Email sending failed";
    ?>
  • Make appropriate changes in $to and $headers variables to set recipient, sender and reply-to address. Save it as “send-mail.php”. (You can save it anywhere or inside any sub-folder in “C:\wamp\www”.)
  • Open this file in browser,

Tuesday 24 July 2012

Create Mysqldata to xml using php


Hi friends, I have code for how to create a xmll file with mysql data using php code.
Follow the below steps to retrieve the data from database to xmlfile

Config.php
<?php

$host="localhost"; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name="test"; // Database name
mysql_connect("$host", "$username", "$password")or die("cannot connect");

mysql_select_db("$db_name")or die("cannot select DB");
?>


Xmlcreate.php

<?php
                include("config.php");
                $query = "SELECT * FROM product";
                $result = mysql_query($query);
                $file= fopen("results.xml", "w");
                $_xml ="<?xml version=\"1.0\" encoding=\"UTF-8\" ?>";
                $_xml .= "<table>\n";
                while ($row = mysql_fetch_array($result)) {
                if ($row[1]) {
                $_xml .="\t<id title=\"".$row[0]."\">";
                $_xml .="\t<name>".$row[1]."</name>";
                $_xml .="\t<q>".$row[2]."</q>";
                $_xml .="\t<price>".$row[3]."</price>";
                $_xml .="\t</id>\n";
                } else {
                $_xml .="\t<id title=\"Nothing Returned\">";
                $_xml .="\t<file>none</file>";
                $_xml .="\t</id>";
                } }
                $_xml .="</table>";
                fwrite($file, $_xml);
                fclose($file);
echo "XML has been written.<a href=\"result.php\">View the XML.</a>";
?>

Result.php

<?php
        include("config.php");
        $xml = simplexml_load_file("results.xml");
                echo $xml->asXML();
?>

Monday 23 July 2012

How To Create excel file with Mysql Data using php Code.


Hi friends, I have code for how to create a excel file with mysql data using php code.
Follow the below steps to retrieve the data from database
Config.php
<?php

$host="localhost"; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name="test"; // Database name
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
?>

a.php

<?php
          include("config.php");
          $filename = "excelwork.xls";
          $exists = file_exists('excelwork.xls');
          if($exists)
          {
                   unlink($filename);
          }
                   $filename = "excelwork.xls";
                   $fp = fopen($filename, "wb");
                   $sql = "select * from product";
                   $result = mysql_query($sql);
                   $schema_insert = "";
                   $schema_insert_rows = "";
                   for ($i = 1; $i < mysql_num_fields($result); $i++)
                   {
                   $insert_rows .= mysql_field_name($result,$i) . "\t";
                   }
                   $insert_rows.="\n";
                   fwrite($fp, $insert_rows);
                   while($row = mysql_fetch_row($result))
                   {
$insert = $row[1]. "\t" .$row[2]. "\t".$row[3]. "\t".$row[4]. "\t".$row[5];
                   $insert .= "\n";               //       serialize($assoc)
                   fwrite($fp, $insert);
                   }
                   if (!is_resource($fp))
                   {
                             echo "cannot open excel file";
                   }
                   echo "success full export";
                   fclose($fp);
?>
This is the steps to create excel file with mysql data using php code.
Once u run a.php it create excelwork file.

Saturday 21 July 2012

PHP Login Page with MD5 possword





 DATABASE

CREATE TABLE admin
(
id INT PRIMARY KEY AUTO_INCREMENT,
username VARCHAR(40) UNIQUE,
password VARCHAR(40)
); 

CODE



config.php

<?php
$host="localhost"; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name="test"; // Database name
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
?>
 
 Login.php

<?php
include("config.php");
if(isset($_POST['submit']))
{
session_start();
$name = $_POST["username"];
$password = $_POST["psw"];
$password = md5($password);
$sql = "select * from login where username ='".$name."' and  password ='".$password."' ";
$result=mysql_query($sql);
$count = mysql_num_rows($result);
if($count==1)
{   
     while($row=mysql_fetch_row($result))
    {   
                   $_SESSION['username'] = $_POST['username'];
            header("Location: user.php");
       }
}
else
{
    header("Location: login.php");
}
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>

<script type="text/javascript">
function change(){
   
    var uname = document.getElementById("username").value;
    var psw = document.getElementById("psw").value;
    //alert(uname);
    if(uname == "")
    {   
        document.getElementById('u').innerHTML = 'Plese Enter User name';
    }
    else
    {
        document.getElementById('u').innerHTML = '';
    }
}
function changep(){
       var psw = document.getElementById("psw").value;
    if(psw == "")
    {
        document.getElementById('p').innerHTML = 'Plese Enter Password';
    }
    else
    {
        document.getElementById('p').innerHTML = '';
    }
}
</script>
</head>
<body><center>
<form action="" method="post">
<table width="503" height="117" border="0">
  <tr>
    <td width="117">User Name</td>
    <td width="160"><input type="text" id="username" name="username" onblur="change()"/></td>
    <td width="260"><label id="u"> </label></td>
  </tr>
  <tr>
    <td>Password</td>
    <td><input type="password" name="psw" id="psw" onblur="changep()" /></td>
    <td width="260"><label id="p"> </label></td>
  </tr>
   <tr>
    <td><input type="reset"  /></td>
    <td><input type="submit" value="submit" id="submit"  name="submit"/></td>
  </tr>
</table>
</form>
</center>
</body>
</html>


user.php

<body>
<h1>Welcome </h1>
</body>

Twitter Delicious Facebook Digg Stumbleupon Favorites More