View Full Version : Using PHP to connect to a foxpro database

11-23-2006, 04:08 AM

My work have given me the job of making their website connect to their accounts server which uses a foxpro free table database. Both the webserver(windows) and accounts server are on the same network, I just cant seem to get it to work, what ive done is...

Created an ODBC connection on the webserver, connecting to accounts server.

Put this code in a file on the webserver.


//connect to database
$connectionstring = odbc_connect("Vision.dsn", "", "");

//SQL quyery

//execute query
$queryexe = odbc_do($connectionstring, $Query);

//output results to standard output
odbc_result_all($queryexe, "BORDER=1");

//diconnect from database


And when running that script i get the error

Warning: odbc_do() [function.odbc-do]: SQL error: [Microsoft][ODBC Visual FoxPro Driver]File 'customer.dbf' does not exist., SQL state S0002 in SQLExecDirect in E:\CBTechWeb\vision\dbconnect.php on line 10

Warning: odbc_result_all(): supplied argument is not a valid ODBC result resource in E:\CBTechWeb\vision\dbconnect.php on line 13

Any help on how to get this working would be great.


11-23-2006, 05:29 AM
Check that the server has a system odbc connection for the database.

11-23-2006, 06:19 AM
Yep its a system odbc pointing to v:\Vision\Home\Sample (im only using a sample database at the moment)

11-23-2006, 06:28 AM
SELECT * FROM customer

case sensitive...

11-23-2006, 06:33 AM
Does'nt make a difference :(

11-23-2006, 06:38 AM
This may be a stupid question, but are you sure there's a table in the db called customer?

11-23-2006, 06:43 AM
Here is a screenshot :)


I know it says "Customer' (uppercase C), but ive tried all different variations and it doesnt make a difference.

I have tried several different tables too.

11-23-2006, 07:18 AM
It is apparently connecting to something but not where the customer.dbf file can be found, so this purely a guess, perhaps a trailing slash on the connection - v:\Vision\Home\Sample\

11-23-2006, 12:19 PM
Tried that. No luck

11-23-2006, 02:28 PM
try echoing the out put of odbc_tables() to see what tables are in the db it's connecting to (not sure if this is correct for odbc functions ):

$connectionstring = odbc_connect("Vision.dsn", "", "");
$tables = odbc_tables( $connectionstring );
echo "<table>\n";
echo " <tr>\n";
echo " <td>Qual.</td>\n <td>Name</td>\n<td>Type</td>\n <\tr>\n";
do {
echo " <tr>\n";
echo ' <td>'.$tables['TABLE_QUALIFIER']."</td>\n";
echo ' <td>'.$tables['TABLE_NAME']."</td>\n";
echo ' <td>'.$tables['TABLE_TYPE']."</td>\n";
echo " <\tr>\n";
} while ( $tables = odbc_tables( $connectionstring ) );
echo '</table>';

At least that will tell you if you're barking up the wrong tree.

11-23-2006, 11:19 PM

its something to do with network problems i think. All that script done was print out a heap of "<r>"s

I decided to make a copy of the database, and put it locally on the webserver, and connect to that, and it worked fine. So there must be some permissions, However when on the server, i have the accounts server as a mapped network drive, i can access the files and everything fine. So im not sure, any ideas?

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum