RE: Linux/PHP/Access Database - oh boy :(

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Thank you Trevor!

Funny you should mention ADOdb.  I just d/l it and uploaded it to my web
site!  I am working through the docs now.  I was losing hope because I
couldn't find what I was looking for but if you don't mind I will help
myself to your connection string:
 
case "OtherDB":
    # Sample connect string to Access MDB file
    $myDSN="PROVIDER=MSDASQL;DRIVER={Microsoft Access Driver
(*.mdb)};Dbq='C:\Database.mdb';UID=;PWD=;";
 
I have been using the realpath function of PHP in other connection strings
to map the path from the server root to the database location.  I assume
will work fine here:
 
  $myDSN="PROVIDER=MSDASQL;DRIVER={Microsoft Access Driver (*.mdb)}; Dbq=".
realpath("prices/mydb.mdb") .";UID=;PWD=;";
 
I'm still not sure this will work.  I'm getting a lot of information from
people saying a .mdb file (the MS Access database) just can't be accessed
this way and I should use an intermediate database format, like .dbf which
can be made by exporting the database out of MS Access into  "dbase 5".
 
Does anyone know what the connection string for a .dbf (dbase 5) format
database is?
 
Alex
|:| Reply-to:  <mailto:alex.gemmell@xxxxxxxxxx> alex.gemmell@xxxxxxxxxx |:|
  _____  

From: Gryffyn, Trevor [mailto:TGryffyn@xxxxxxxxxxxxxxxxx] 
Sent: 12 May 2004 15:09
To: PHP List
Cc: Alex Gemmell
Subject: RE:  Linux/PHP/Access Database - oh boy :(
 
First, I don't think you are likely to use COM calls on a linux box since
COM and DCOM are MS things aren't they?   Even if not, it might require some
configuration on the server end which you can't do.
 
I use the ADOdb database library for PHP in all the things I do:
http://php.weblogs.com/adodb
 
I have a dbconnect.inc file that has all my connect strings in a switch/case
statement that dynamically changes the connect string.
 
I think you can connect DSNLess to an Access database this way.
 
I'll paste a stripped down version of the dbconnect.inc to my message since
I don't know if this list accepts attachments.   Let me know if you have any
questions.. good luck!
 
-TG
 
<?php
include("adodb/adodb.inc.php");
 
ADOLoadCode("ado_mssql");
$db = &ADONewConnection("ado_mssql");
 
switch ($database) {
  ################################################################
  # Cargo System databases
  ################################################################
 
  case "PhotoGallery":
    # Where the photos are stored
    $myDSN="PROVIDER=MSDASQL;DRIVER={SQL
Server};SERVER=PhotoServe;DATABASE=Photos;UID=username;PWD=password;";
    break;
  case "UserLogin":
    # Where the user login information is
    $myDSN="PROVIDER=MSDASQL;DRIVER={Microsoft ODBC for
ORACLE};SERVER=TMPROD;UID=ops;PWD=ops;";
    break;
  case "OtherDB":
    # Sample connect string to Access MDB file
    $myDSN="PROVIDER=MSDASQL;DRIVER={Microsoft Access Driver
(*.mdb)};Dbq='C:\Database.mdb';UID=;PWD=;";
    break;
}
 
$db->Connect($myDSN);
#$db->debug=true;
 
if ($sqlquery <> "") {
  $rs = $db->Execute($sqlquery);
  if ($rs === false) {
    print "<h2>Error: (" . $db->ErrorNo() . ") " . $db->ErrorMsg() .
"</h2><br>\n";
  } else {
    $arr = $rs->GetArray();
    print "Status: (" . $db->ErrorNo() . ") " . $db->ErrorMsg() . "<br>\n";
  }
} else {
  $rs = $db->Execute($sql);
  if ($rs === false) {
    print "<h2>Error: (" . $db->ErrorNo() . ") " .
$db->ErrorMsg()."<br>$sql<br>\n";
  }
}
 
$sqlquery = "";
$sql = "";
 
$db->Close();
?>
-----Original Message-----
From: Alex Gemmell [mailto:alex.gemmell@xxxxxxxxxx] 
Sent: Wednesday, May 12, 2004 8:12 AM
To: PHP List
Subject:  Linux/PHP/Access Database - oh boy :(
Hello all,
 
I am fairly new to Linux/PHP so please bear with me.  I have an awfully
awkward problem to solve - a stop gap solution for the next 6 months until
we have out in-house servers set up and running.  I also have a very short
timeframe to sort this out.  I am using PHP on a remotely hosted Linux web
server to build my website, however I have been given a MS Access database
to use!  Despite my best efforts (and two days Google trawling) I haven't
found a suitable solution so I am turning to your collective knowledge.
 
First things first - I do not run the server and cannot install any new
tools on to it (I cannot access the folders above my web root).  There are
lots of suggestions on the net about installing MDBTools and UnixODBC RPM
(http://bryanmills.net:8086/archives/000099.html) - but that involves the
admin who won't do it!  I can, of course, put scripts that may help in the
actual web folder and reference them if anyone has any ideas.
 
I know I must use a DSN-less connection.  I first tried connecting directly
to the mdb file using:
       $conn = new COM("ADODB.Connection") or die ("Cannot create ADODB
Connection object."); 
       
       //$connstr =
"PROVIDER=MSDASQL;DBQ=/prices/mydb.mdb;"."DRIVER={Microsoft Access Driver
(*.mdb)};" 
       //$connstr = "Provider=Microsoft,.Jet.OLEDB.4.0; Data Source=".
realpath("prices/mydb.mdb") ." ;";
       // I've never got the above two connection strings to work but I
include them for completeness and in case any realises they might help me!
       $connstr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=".
realpath("prices/mydb.mdb") ." ;";
 
$conn->open($connstr);
 
This worked on my localhost running IIS 5 (unsurprisingly) but fell over
immediately on the Linux box.  I am told this is because COM support in PHP
before version 4.3.x is buggy (he PHP version installed on the server is
4.1.2).  Is this true?  Will upgrading to version 4.3.x solve all my
problems?
 
Also, I heard that converting the .mdb file to a .dbf file might help - but
how do I connect to that with PHP?  The PHP manual says this about dbase
functions:
"These functions allow you to access records stored in dBase-format (dbf)
databases. There is no support for indexes or memo fields."
That's no good because I have long text fields in the Access database that
are of type "memo"!
The Manual also says "we recommend that you do not use dBase files as your
production database" - eek!  It's only a small database (one table with
about 50 records, each with no more than 20 fields) so hopefully it will
suffice.
 
Am I right in thinking I have very few options?   I don't want to move over
to ASP (would that even help?) because it means learning VBScript and I
don't have a lot of time.  Also, I can't use another database (e.g. MySQL)
cos the server admin is NOT helping me and won't install anything new.
 
I know 99% of you will want to tell me to just back out of this horrible
tangle and take a different route, but is there one person out there who can
help me get through this nightmare?
 
Thank you!
 
Alex Gemmell
|:| Reply-to:  <mailto:alex.gemmell@xxxxxxxxxx> alex.gemmell@xxxxxxxxxx |:|
 
Or call me for free using Skype: 
 <callto://alex.gemmell/> 
 

[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux