Koozali.org: home of the SME Server

access database on SMEServer

Offline schlagg

  • 12
  • +0/-0
access database on SMEServer
« on: November 12, 2007, 03:06:33 PM »
Hello,

here's my question :

actually, i've a part of my website on a windows server (Apache2 and PHP 5.2.3)
On this website, i've a PHP script which allows a connection with an MS Access database :

Code: [Select]
...
$connectionString = sprintf("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=%s", $chemin_complet);
$cnx = odbc_connect($connectionString, "", "");
$ressource_ta  = odbc_exec($cnx, "SELECT C.date, valeur FROM access_base C ORDER BY date DESC");
...

This works very fine.
But now, i want to move this part of my website to my sme-server : 7.2 with PHP 4.3.9 and Apache2
i copy the Acess DB to an SME ibay and change its dir in the php script, but the script won't work, and i've no error to report  :sad:

what i've missed?

Thanks for your help.

Offline cactus

  • *
  • 4,880
  • +3/-0
    • http://www.snetram.nl
Re: access database on SMEServer
« Reply #1 on: November 12, 2007, 07:00:18 PM »
Hello,

here's my question :

actually, i've a part of my website on a windows server (Apache2 and PHP 5.2.3)
On this website, i've a PHP script which allows a connection with an MS Access database :

Code: [Select]
...
$connectionString = sprintf("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=%s", $chemin_complet);
$cnx = odbc_connect($connectionString, "", "");
$ressource_ta  = odbc_exec($cnx, "SELECT C.date, valeur FROM access_base C ORDER BY date DESC");
...

This works very fine.
But now, i want to move this part of my website to my sme-server : 7.2 with PHP 4.3.9 and Apache2
i copy the Acess DB to an SME ibay and change its dir in the php script, but the script won't work, and i've no error to report  :sad:

what i've missed?

Thanks for your help.

Have a look in the /var/log/messages file and the /var/log/httpd/error_log files at the time you were trying (e.g. the error occurred). I once posted this in the wiki to (temporarily) enable the display of error messages: http://wiki.contribs.org/PHP#Display_Error_Messages
Be careful whose advice you buy, but be patient with those who supply it. Advice is a form of nostalgia, dispensing it is a way of fishing the past from the disposal, wiping it off, painting over the ugly parts and recycling it for more than its worth ~ Baz Luhrmann - Everybody's Free (To Wear Sunscreen)

Offline schlagg

  • 12
  • +0/-0
Re: access database on SMEServer
« Reply #2 on: November 13, 2007, 10:13:41 AM »
Quote
Have a look in the /var/log/messages file and the /var/log/httpd/error_log files at the time you were trying (e.g. the error occurred).

No error concerning this script in those files.

My MS Access Database is located in :

Windows server :
C:\Program Files\Test\AccessDB

so the script is :
Code: [Select]
$chemin_complet = 'C:\\Program Files\\Test\\AccessDB';
$connectionString = sprintf("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=%s", $chemin_complet);


SME Server
/home/e-smith/files/ibays/doctest/files/AccessDB

i change the script to :
Code: [Select]
$chemin_complet = 'home//e-smith//files//ibays//doctest//files//AccessDB'
$connectionString = sprintf("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=%s", $chemin_complet);

i've made test with simple "/", with "//", "\", or "\\"
but nothing work

is there something else to do or connect to a MS database is not possibe with a linux server??

Thanks for your answers ..

Offline cactus

  • *
  • 4,880
  • +3/-0
    • http://www.snetram.nl
Re: access database on SMEServer
« Reply #3 on: November 13, 2007, 10:29:43 AM »
i change the script to :
Code: [Select]
$chemin_complet = 'home//e-smith//files//ibays//doctest//files//AccessDB'
$connectionString = sprintf("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=%s", $chemin_complet);

i've made test with simple "/", with "//", "\", or "\\"
but nothing work

is there something else to do or connect to a MS database is not possibe with a linux server??

Thanks for your answers ..
Linux does not have native support for MS Access like windows does as you seem to build an ODBC connection in your application. BTW Why don't you have trailing slashes in the path to the access database, like //home/e-smith//...?

Is there an error returned in the php script when you connect? You are only building the connection string here and not actually connecting to the database.
Be careful whose advice you buy, but be patient with those who supply it. Advice is a form of nostalgia, dispensing it is a way of fishing the past from the disposal, wiping it off, painting over the ugly parts and recycling it for more than its worth ~ Baz Luhrmann - Everybody's Free (To Wear Sunscreen)

Offline schlagg

  • 12
  • +0/-0
Re: access database on SMEServer
« Reply #4 on: November 13, 2007, 10:58:48 AM »
Linux does not have native support for MS Access like windows does as you seem to build an ODBC connection in your application. BTW Why don't you have trailing slashes in the path to the access database, like //home/e-smith//...?

i made this already, but same thing

Quote
Is there an error returned in the php script when you connect? You are only building the connection string here and not actually connecting to the database.

No error
and after the connection string, i connect to the db with :
Code: [Select]
$cnx = odbc_connect($connectionString, "", "");
$reponse = odbc_exec($cnx, "SELECT C.date, Value FROM test C ORDER BY date DESC");

But if there is no support for Access DB, i think i'm good for an Access / MySQL convertion ....

Thanks again.

Offline cactus

  • *
  • 4,880
  • +3/-0
    • http://www.snetram.nl
Re: access database on SMEServer
« Reply #5 on: November 13, 2007, 12:24:56 PM »
No error
and after the connection string, i connect to the db with :
Code: [Select]
$cnx = odbc_connect($connectionString, "", "");
$reponse = odbc_exec($cnx, "SELECT C.date, Value FROM test C ORDER BY date DESC");
Are you sure there is no error? I do not see any error code checking in your code, perhaps you should read up on PHP and ODBC (http://www.php.net/manual/en/ref.uodbc.php).

I am wondering what would be the result if you change your two lines of code to this:
Code: [Select]
//Set display_errors parameter to On
ini_set('display_errors', 'On');

//Connect and check for error
$cnx = odbc_connect($connectionString, "", "");
if (odbc_error($cnx) != "") die (odbc_error($cnx) . ": " . odbc_errormsg($cnx));
 
//Query and check for error
$reponse = odbc_exec($cnx, "SELECT C.date, Value FROM test C ORDER BY date DESC");
if (odbc_error($cnx) != "") die (odbc_error($cnx) . ": " . odbc_errormsg($cnx));
Be careful whose advice you buy, but be patient with those who supply it. Advice is a form of nostalgia, dispensing it is a way of fishing the past from the disposal, wiping it off, painting over the ugly parts and recycling it for more than its worth ~ Baz Luhrmann - Everybody's Free (To Wear Sunscreen)

Offline schlagg

  • 12
  • +0/-0
Re: access database on SMEServer
« Reply #6 on: November 19, 2007, 11:03:30 AM »
Code: [Select]
//Set display_errors parameter to On
ini_set('display_errors', 'On');

//Connect and check for error
$cnx = odbc_connect($connectionString, "", "");
if (odbc_error($cnx) != "") die (odbc_error($cnx) . ": " . odbc_errormsg($cnx));
 
//Query and check for error
$reponse = odbc_exec($cnx, "SELECT C.date, Value FROM test C ORDER BY date DESC");
if (odbc_error($cnx) != "") die (odbc_error($cnx) . ": " . odbc_errormsg($cnx));

Ok, i've got some times to tests the code, and you're right there is an error :
Code: [Select]
Fatal error: Call to undefined function: odbc_connect() in /home/e-smith/files/ibays/Primary/html/tests/test.php on line 117

so the odbc functions are not defined.
is there a way to define them?

Thanks ...

Offline Elliott

  • ***
  • 150
  • +0/-0
Re: access database on SMEServer
« Reply #7 on: November 19, 2007, 07:36:49 PM »
Unix ODBC is explained here:

http://www.unixodbc.org/

I've used these open source ODBC setups to get linux machines to talk to external MS SQL databases. Seems to me you should be able to get it working with local files too.

-E
Elliott

Offline schlagg

  • 12
  • +0/-0
Re: access database on SMEServer
« Reply #8 on: November 21, 2007, 10:14:44 AM »
Hello

finally, seems to work, but can we put a dynamic name to the database??

i explain : my application create a new MS Access Database per month
exemple :
in octobre i've ../DB/2007/10/database1.mdb, database2.mdb
in novembre, i've ../DB/2007/11/database1.mdb, database2.mdb

etc ...

in windows server, i can access to them in PHP with variables in the Database Dir ...

but, in Linux server, it seems that we have to put the databe Dir in a "static" file : /etc/odbc.ini

Code: [Select]
[vo20]
Description = Microsoft Access Database of vo20
Driver = MDBToolsODBC
Database = ../ibay/DB/2007/10/database1.mdb
Servername = localhost
UserName =
Password =
port = 5432

so, how can i change dinamycally the Database dir??

Thanks a lot.

Offline Elliott

  • ***
  • 150
  • +0/-0
Re: access database on SMEServer
« Reply #9 on: November 21, 2007, 03:26:18 PM »
I'm not positive on an answer here. I would suggest a cron job that runs a script at the beginning of each month to recreate the odbc.ini file with the correct path. Your script could use the $date command and then parse it out to the correct string to write the file out.

I doubt that you can actually make the odbc.ini dynamic itself but I haven't read the entire set of docs on their site.

-E
Elliott