Sunday, October 5, 2014

PHP Fatal error: Call to undefined function session_register()

session_register() has been DEPRECATED as of PHP 5.3.0 and REMOVED as of PHP 5.4.0.

Your facing this problem because of you are using PHP 5.4.0 or above

Read PHP documentation
http://www.php.net/manual/en/function.session-register.php


For solution : Remove  session_register() from you code.

Tuesday, August 12, 2014

Select data beween two row number of result set (LIMIT IN MSSQL)

In MYSQL, LIMIT  clause is used to select records from the beginning, middle and end of a result set.
The LIMIT clause accepts one or two arguments. The values of both arguments must be zero or positive integer constants.

Select * from Tablename LIMIT offset,count

Here offset specifies the offset of the first row to return and count specifies maximum number of rows to return.

But in MSSQL it can get different way. TOP Clause is used to specify the number of records to return.

SELECT TOP number|percent columnname(s)
FROM tablename


MSSQL SERVER Does not support LIMIT clause. You can implement it in different way. Suppose you want to select rows between 6 to 10, you should try below MSSQL query

SELECT * FROM (
  SELECT *, ROW_NUMBER() OVER (ORDER BY table_column) as row FROM Tablename
 ) a WHERE row > 5 and row <= 10


 

Saturday, June 28, 2014

India date and time in php

India date & time can get by setting indian zone and using date function of php. Use Below code

<?php

date_default_timezone_set('Asia/Calcutta');
echo date("H:i");
echo date("d-M-Y");

?>

Friday, June 27, 2014

How to get two date which in varchar type is equal are not in PHP

Suppose we have two date field or two date from SQL result and we want to find out if the eual or not, then you can try below cod code
if ( strtotime($date1) == strtotime($date2) )
{
 echo "date is equal";
}

Friday, May 30, 2014

The following from address failed in phpmailer code error using gmail Id

I have php source code which is used to send email. I have used phpmailer class and gmail id to send mail. It was working fine from last 1 year But  currently it stop working and through below error:
"The following From address failed: your@gmail.com"

Below was my source code :
<?php
require_once("class.phpmailer.php");
$mail = new PHPMailer(); 
$body="email body \n";
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPDebug  = 1;      // enables SMTP debug information (for testing)
                                                // 1 = errors and messages
                                              // 2 = messages only
  $mail->SMTPAuth   = true;                  // enable SMTP authentication
  $mail->SMTPSecure = "ssl";                 // sets the prefix to the servier
  $mail->Host      = "smtp.gmail.com";    // sets GMAIL as the SMTP server
  $mail->Port       = 465;                       // set the SMTP port for the GMAIL server
  $mail->Username   = "your-gmail-Id@gmail.com";  // GMAIL username
  $mail->Password   = "gmail password";            // GMAIL password  
  $mail->SetFrom('your-gmailid@gmail.com', 'Metropolis Delhi'); 
  $mail->AddReplyTo('your-gmailid@gmail.com', 'Metropolis Delhi');
  $mail->Subject    ="Email Subject";    
  $mail->Body =$body;
   if(!$mail->Send())
    {
       echo $mail->ErrorInfo;
      return false;
    }
    else
    {
      echo "Email Sent to !". $collname;
      }
?>

To solve this problem, First I login to gmail and go to ''setting' => Account and Import => update correct "Send mail as"  i.e. correct "From name" and email.

But problem is still not solved.

Now I change ssl to tls and port no 587 in my code.
 Now it is working fine. Below is code which is working fine.

<?php
require_once("class.phpmailer.php");
$mail = new PHPMailer(); 
$body="email body \n";
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPDebug  = 1;      // enables SMTP debug information (for testing)
                                                // 1 = errors and messages
                                              // 2 = messages only
  $mail->SMTPAuth   = true;                  // enable SMTP authentication
  $mail->SMTPSecure = "tls";                 // sets the prefix to the servier
  $mail->Host       = "smtp.gmail.com";    // sets GMAIL as the SMTP server
  $mail->Port       = 587;                       // set the SMTP port for the GMAIL server
  $mail->Username   = "your-gmail-Id@gmail.com";  // GMAIL username
  $mail->Password   = "your-password";            // GMAIL password  
  $mail->FromName="From Name";  // correct from name
  $mail->From="your-gmailId@gmail.com";
  $mail->AddReplyTo('your-gmail-Id@gmail.com', 'Metropolis Delhi');
  $mail->Subject    ="Email Subject";    
  $mail->Body =$body;
   if(!$mail->Send())
    {
       echo $mail->ErrorInfo;
      return false;
    }
    else
    {
      echo "Email Sent to !". $collname;
      }
?>