Hi,

Long time reader, first time poster! I am new to php coming from
a generally MS (unfortunately) background (Access, VB, SQLServer)
and I am looking to branch out a bit.

I have a client who wishes to have an internet front-end to an
Access database. I am using php with odbc to access this and (as
I am a newbie), I am having problems with the connection. After
I do an odbc_pConnect, when I call the odbc_exec, I get the usual
error, Warning: Supplied agrument is not a valid ODBC-Link resource.

The ODBC DSN is setup as standard (no default login etc). The
following code is being used for db access:

function DBRetrieve($pSQLStr)
{
   global $DBConn, $DBQryID, $DBQryRows, $DBQryColumns;

   $DBDsn='PHPTEST';
   $DBUser='Admin';
   $DBPassword ='';

   #Open a persistent connection to the database
   if (!$DBConn = (odbc_pConnect($DBDsn, $DBUser, $DBPassword) or die("Database 
Execution Error: " . odbc_Error() . " " .  odbc_ErrorMsg())))
   {
     echo "\nError connecting to database\n";
     return false;
   }

   #Send query to database
   if (!$DBQryID=(odbc_Exec($DBConn, $pSQLStr) or die("Database Execution Error: " . 
odbc_Error() . " " .  odbc_ErrorMsg())))
   {
     echo "\nError executing database request: [ODBC_EXEC]\n";
     DBDestroy();
     return false;
   }

   #Get no of rows in recordset
   if (!$DBQryRows=(odbc_num_rows($DBQryId) or die("Database Execution Error: " . 
odbc_Error() . " " .  odbc_ErrorMsg())))
   {
     echo "\nError executing database request: [ODBC_NUM_ROWS]\n";
     DBDestroy();
     return false;
   }

   #Get number of fields to display
   if (!$DBQryColumns=(odbc_num_fields($DBQryId) or die("Database Execution Error: " . 
odbc_Error() . " " .  odbc_ErrorMsg())))
   {
     echo "\nError executing database request: [ODBC_NUM_FIELDS]\n";
     DBDestroy();
     return false;
   }

   return true;
}

Does this look ok to you more experienced guys? Am I missing
something or is there a better way?

Thanks.

Colum

--------------------------------------------------------------------
Mail2Web - Check your email from the web at
http://www.mail2web.com/ .


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to