<?php
$myServer = "202.138.125.155";
$myUser = "micro_fms";
$myPass = "micro_fms*#$";
$myDB = "micro_fms"; 

//create an instance of the  ADO connection object
$conn = new COM("ADODB.Connection")or die("Cannot start ADO");

//define connection string, specify database driver
$connStr = "PROVIDER='SQLOLEDB'; SERVER=".$myServer.";UID=".$myUser.";PWD=".$myPass.";DATABASE=".$myDB; 

//Open the connection to the database
$conn->open($connStr);

//$table_name=$_GET['Device'];
$table_data=$_GET['Data'];
$data=(explode(",",$table_data));

$table_name=$data[0];
$speed=$data[1];
$time=$data[2];
$date=$data[3];
$lat=$data[4];
$long=$data[5];
//$newdate = substr($date,6,2) . "-" . substr($date,0,2) . "-" substr($date,3,2);
$datetime=$date.$time;


$new_lat = substr($lat,0,2).'.'.substr($lat,2);
$new_long = substr($long,0,2).'.'.substr($long,2);

echo $table_name."<br>";
echo $speed."<br>";
echo $new_lat."<br>";
echo $new_long."<br>";
echo $datetime."<br>";

$query="insert into $table_name (DeviceNumber,Speed,dtDateTime,Latitude,Longitude)values('$table_name','$speed','$datetime','$new_lat','$new_long')";


//execute the SQL statement and return records
$rs = $conn->execute($query);
if($rs)
{
echo 'Values Inserted';
}
else
{
echo "faile";
}
?>

Hi friends...
I have two variables ($date and $time). I concat these two strings and make a new variable called "$datetime". Now in above code I want to insert it into table but I got the following error.

Fatal error: Uncaught exception 'com_exception' with message '<b>Source:</b> Microsoft OLE DB Provider for SQL Server<br/><b>Description:</b> Conversion failed when converting datetime from character string.' in C:\wamp\www\FMS\fms.php:44 Stack trace: #0 C:\wamp\www\FMS\fms.php(44): com->execute('insert into A00...') #1 {main} thrown in C:\wamp\www\FMS\fms.php on line 44

In my database, data type of column in which I want to insert is Date time stamp though I have string type ($datetime) variable.
I think I have to convert this $datetime variable string to "DateTime type first but don't have any idea about it.
Please help??/
Thanks in advance....

Could you post the string $datetime ? Anyway, strtotime or date_create might do the job.

Could you post the string $datetime ? Anyway, strtotime or date_create might do the job.

Thanks for your reply..
This $datetime can't insert in database and throw out of range error.
I have a one more requirement also.
Now, I want in $time variable add 5:30:00 and store in time format( so that it can be insert it in database) and I have date in ddmmyy format but in string type which i have to convert it in date mm-dd-yyformat ( again so that it can be insert it in database).
How can I do these???

Look into those functions to parse your string; add those 5:30 in seconds (5*60*60+30*60) and format it with date or date_format or so. Just look up those functions to see how to use them.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.