0

hi,

I have date in this format
December 2 2009
December 2 2009
December 2 2009

and i want to insert it in my table in mysql .I m inserting this with the help of perl
means i m doing my program in perl .ook at my program

#!/usr/bin/perl

use Mysql;
use DBI;
my $dataSourceName = "DBI:mysql:database=redbytes_TestDrupal;host=localhost";
@file =  "submission.csv";
my($date , $name ,$emailid , $phone ,$country ,@value , @raw_data);
# MYSQL CONFIG VARIABLES
$host = "localhost";
$database = "redbytes_TestDrupal";
$tablename = "submissionfiledata";
$user = "redbytes";
$pw = "N1nja2007";

# PERL MYSQL CONNECT()
$con = DBI->install_driver('mysql'); 
$con = $con->connect($dataSourceName, $user,$pw); 

foreach my $filename(@file)
{
	open(DAT,$filename)||die("Could not open file!");
	@raw_data = <DAT>;
	close(DAT);
	print $filename(@raw_data);
	foreach my $line(@raw_data)
	{
		chomp($line);
		@value = split(',',$line);
		$date = @value[0];
		$name = @value[2];
		$emailid = @value[3];
		$phone = @value[5];
		$country =@value[6];
		#print($date);
		if(!$con)
		{
			die('Could not connect: ' . mysql_error());
		}
		else
		{
			my $sql = "INSERT INTO submissionfiledata "."(date,Name,FromEmailid,PhoneNumber,CountryName) "."VALUES "		."('$date','$name','$emailid','$phone','$country')";
			$query = $con->prepare($sql);
			$query->execute();
			if(! $query )
			{
				die('Could not enter data: ' . mysql_error());
			}
			
		}
	}
}
print( "Entered data successfully\n");

when i run this then it inserting date 0000-00-00

but i want here date ...........

Plz help me

Edited by peter_budo: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)

2
Contributors
1
Reply
3
Views
7 Years
Discussion Span
Last Post by urtrivedi
0

use str_to_date() function of mysql

$sql = "INSERT INTO submissionfiledata "."(date,Name,FromEmailid,PhoneNumber,CountryName) "."VALUES " .
"(str_to_date('{$date}' ,'%M %d %Y') ,  '$name','$emailid', '$phone','$country')";

Edited by urtrivedi: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.