When I run the script below, I get the number of rows returned in the query appended to the file. What I really need is the query result appended to the file.
Thanks,
Rob
<?
$id = $_REQUEST['id'];
//Connect to the test database
$odbc = odbc_connect ('test', 'test', 'test') or die( "Could Not Connect to ODBC Database!" );
//Access query to pull the info we want, it runs in access
$query = odbc_exec($odbc, "SELECT tblCustomer.CustomerKey, tblCustomer.CustomerID, tblCustomer.FirstName, tblCustomer.LastName, tblCustomer.Company, tblCustomer.AddressLine1, tblCustomer.AddressLine2, tblCustomer.City, tblCustomer.MailCode, tblCustomer.WorkNumber, tblCustomer.HomeNumber, tblCustomer.MobileNumber, tblCustomer.EMailAddress, tblCustomer.ContactMethod, tblCustomer.CollectionMethod, tblCustomer.BillType, tblCustomer.Notes, tblService.ServiceKey, tblService.ServiceID, tblService.CustomerKey, tblService.ServiceType, tblService.Status, tblService.StartDate, tblService.EndDate, tblService.Login, tblService.Password, tblService.Timebank, tblService.Profile, tblService.Notes FROM tblCustomer INNER JOIN tblService ON tblCustomer.CustomerKey = tblService.CustomerKey WHERE tblCustomer.CustomerID='$id'") or die (odbc_errormsg());
//Without the WHERE above this will return ALL customer into file. HUGE File will lock up server.
$result = odbc_result_all($query);
$filename = 'rob.txt';
$somecontent = "$result\r\n";
// Let's make sure the file exists and is writable first.
if (is_writable($filename)) {
// In our example we're opening $filename in append mode.
// The file pointer is at the bottom of the file hence
// that's where $somecontent will go when we fwrite() it.
if (!$handle = fopen($filename, 'a')) {
echo "Cannot open file ($filename)";
exit;
}
// Write $somecontent to our opened file.
if (fwrite($handle, $somecontent) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}
echo "Success, wrote ($somecontent) to file ($filename)";
fclose($handle);
} else {
echo "The file $filename is not writable";
}
odbc_close($odbc);
?>