Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ODBC Connection won't work even tho identical on 2 pages?

Status
Not open for further replies.

scriggs

IS-IT--Management
Jun 1, 2004
286
GB
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.

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";

}
 
First in the code you posted, your query is commented out. So $query has nothing when it gets sent.
But i guess that was a typo.
Secondly
It would seem, according to the error that the query has a problem . Try doing
echo $query.

And see if the query string is valid. Try cutting and pasting the query from the browser directly to the db , and executing it. See if the db spits out an error.





----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top