I call an MS Access database from a page on my site which works AOK, everytime. I have copied EXACTLY the code for ODBC connection to another page but when I run on this page I get the error:
"Warning: odbc_do(): SQL error: [Microsoft][ODBC Microsoft Access Driver] Unexpected error from external database driver (11265)., SQL state S1000 in SQLExecDirect in E:\WASP\scripts\files.inc.php on line 325
Error executing query SELECT qryClientsLive.* FROM qryClientsLive WHERE qryClientsLive.ClientCode LIKE 'HOW02%'"
A couple of things I have tried from googling:
1) Manually set the variable passed incase it was a case issue - also changed it to ClientNumber and tried an integer.
2) Setup a duplicate DSN with a different name incase it was being used at the same time.
3) These pages display together so I set PAGE NOT WORKING to a standalone page and still get the error.
"Warning: odbc_do(): SQL error: [Microsoft][ODBC Microsoft Access Driver] Unexpected error from external database driver (11265)., SQL state S1000 in SQLExecDirect in E:\WASP\scripts\files.inc.php on line 325
Error executing query SELECT qryClientsLive.* FROM qryClientsLive WHERE qryClientsLive.ClientCode LIKE 'HOW02%'"
A couple of things I have tried from googling:
1) Manually set the variable passed incase it was a case issue - also changed it to ClientNumber and tried an integer.
2) Setup a duplicate DSN with a different name incase it was being used at the same time.
3) These pages display together so I set PAGE NOT WORKING to a standalone page and still get the error.
Code:
PAGE THAT WORKS
function DisplayODBCData($activeClient)
{
// odbc_query.php
$odbc_dsn = "sagedata_db";
$odbc_userid = "";
$odbc_password = "";
$wordwrap = 18; //cutoff so that the table does not wrap around
$query = "SELECT qryClientsLive.* FROM qryClientsLive where qryClientsLive.ClientCode Like '" . $activeClient . "%'";
if(!($odbc_db = odbc_connect($odbc_dsn, $odbc_userid, $odbc_password)))
die ("Could not connect ot ODBC data source $odbc_dsn");
if(!($odbc_rs = odbc_do($odbc_db, $query)))
die("Error executing query $query");
$num_cols = odbc_num_fields($odbc_rs);
if($num_cols < 1) die("Query returned an empty set");
echo "<table class=\"whitetable\">";
echo "<tr><td>Name:</td></tr><tr><td><b>" . wordwrap(odbc_result($odbc_rs, "ReportName"), $wordwrap, "\n", echo "</table>";
$odbc_rs = null;
$odbc_db = null;
}
Code:
PAGE THAT DOES NOT WORK
function MailMergeDocument($activeClient,$dirname,$template,$type)
{
$outpath = "\\Documents\\";
$letter_dir = "\\Documents\\IT\\Letters\\";
function better_odbc_num_rows($con,$sql){
$result = odbc_exec($con,$sql);
$count=0;
while($temp = odbc_fetch_into($result, &$counter)){
$count++;
}
return $count;
}
print_r ($_POST);
// odbc_query.php
$odbc_dsn = "sagedata_db";
$odbc_userid = "";
$odbc_password = "";
//$query = "SELECT qryClientsLive.* FROM qryClientsLive WHERE qryClientsLive.ClientCode LIKE '" . $_POST['custname'] . "%'";
if(!($odbc_db = odbc_connect($odbc_dsn, $odbc_userid, $odbc_password)))
die ("Could not connect ot ODBC data source $odbc_dsn");
if(!($odbc_rs = odbc_do($odbc_db, $query)))
die("Error executing query $query");
$num_cols = odbc_num_fields($odbc_rs);
if($num_cols < 1) die("Query returned an empty set");
$num = better_odbc_num_rows($odbc_db,$query); // (perhaps show an error if there are no rows returned...)
//set file save variables
$strFileName = strip_ext($template);
$strFileExtension = "." . end(explode('.',$template));
$strFolderPath = $outpath . $_POST['custname'] . "\\";
$strPath = $letter_dir."\\".$dirname."\\".$template;
$strFileName = saveDocument($strPath, $strFolderPath, $strFileName, $strFileExtension);
echo "<p>Your Mail Merge has completed. The letter was saved to <a href=\"" . $strFileName . "\" target=\"_blank\" >" . $strFileName . "</a>.</p>\n";
}