PHP + Access via ODBC problem

hi all,

i have a problem with PHP connecting to a remote Access database via ODBC.

Before you get the chance of answering : MySQL is NOT an option ;) this is a program made in access and used by some people here at work so I can’t use MySQL for this.

Problem : We have a program in an Access database that is located on one of our servers here at work. I was asked to create some reporting on our intranet via PHP from that access database. When I try to connect to the db and retrieve data from it, i get a blank screen in both FF and IE. Both servers, webserver and server where the database resides on, are Windows 2003 server in a domain.

Here’s what I did :

  • on the webserver I created a SystemDSN to the database via a network-mapping
  • programmed this PHP code to test the connection and retrieve some standard data :
<?php
$cnx = odbc_connect( 'lecono' , '', '' );
if (!$cnx) {
    Error_handler( "Error in odbc_connect" , $cnx );
} else { echo "OK!<p>"; }

// send a simple odbc query . returns an odbc cursor
$cur= odbc_exec( $cnx, "select VLEEFGROMS from Leefgroepen" );
if (!$cur) {
    Error_handler( "Error in odbc_exec( no cursor returned ) " , $cnx );
} else
    { echo "Connectie geslaagd!<p>";
    // echo "<table border=1><tr><th>Testveld</th></tr>n";
	$nbrow=0;   //Local variable to count number of rows

    // fetch the succesive result rows
	while( odbc_fetch_row( $cur ) ) {
    	$nbrow++;
        $Testveld= odbc_result( $cur, 1 ); // get the field "VLEEFGROMS"
    
		//    echo "<tr><td>$Testveld</td></tr>n";
		echo "$Testveld<br>"; }

}

// echo "

$nbrow entries ";
// close the connection. important if persistent connection are "On"
odbc_close( $cnx);

?>

If I execute this page however, it returns a blank window in FF & IE. The code works perfectly though because if I put a copy of that database on the webserver and I adjust the SystemDSN, data is returned as it should.

So I suppose this is a security-related problem on the Windows 2003 level.

Any ideas and tips are more than welcome!

Thanks in advance!

Error_handler( "Error in odbc_connect" , $cnx );

What is this Error_handler() function? Try adding a simple echo statement in the first if statement. I have a feeling the echo “OK”; statement doesn’t output anything, nor does the Error_handler() function.

hi there, thanks for the reply…

I have added an echo to the first If but that isn’t displayed if I go to the page. Screen remains white…

In that case it sounds like the script is hanging on the odbc_connect() statement. Try surrounding that statement with echos and see if it stops there. Also use error_reporting(E_ALL).

could it help telling that if i use the SystemDSN to refer to a local copy of the db, it works?

I’ll try the echo"s…

I’m thinking you’re either not permitted to connect to the remote database, or there’s something wrong in the settings of the SystemDSN connection (or perhaps there’s something wrong with your network’s infrastructure). If you can connect in a similar way to a local copy of the same database, then PHP is not your problem :wink:

Sponsor our Newsletter | Privacy Policy | Terms of Service