visitor (0 QPoints)
  • FR
  • EN
  • NL
  • DE
  • ES
315 experts, 1193 registered users, 1659 questions already answered
European Experts Exchange, the very best site for high-quality IT solutions

New Improved Search!

 


05/10/2011 1h30 : Steve Jobs is dead, the father of Apple ][ is gone, we are all orphaned.

ALL :: ZONES :: Connect to an MS Access DB


By: Trutje U.S.A.  Date: 14/05/2003 00:00:00  English  Points: 125 Status: Answered
Quality : Excellent
Hello,

For a genealogical site I found a verry well working consept writen in PHP at <A HREF="http://www.infused.org">www.infused.org</a> build to work with a MySQL DB. But the site I am using is writen in ASP with an MS Access DB as data source. PHP is no problem becouse my profider is supporting PHP. But I don't want a second DB so I want to use MS Access.

I am no expert in PHP so my question is:

Can someone convert the code (included at the end of this posting) so it can work with my MS Access DB?
I've tested a connection from simple PHP to my Access DB and it works (included as well).

So my question is can somone make the first code work by using the second code?

Thanks,

Tr,

----------------------------------code that has to be chanched--------------------------
<?php

db_connect(); //Establish database connection for duration of script

//FUNCTION to connect to database
function db_connect() {
if (!mysql_pconnect("database", "login", "password")) {
print "Could not connect to database server - please try again later";
}
if (!mysql_select_db("database")) {
print "Could not connect to database - please try again later";
}
}

?>
----------------------------------------end of first code-------------------------------------

-----------------------------Working connection sample-------------------------------------------
<?php

$db = "C:\web\database\Erich.mdb";

$conn = new COM("ADODB.Connection");
$conn->Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=$db");


$sql = "SELECT Roepnaam, Naam, email FROM Relatie";
$rs = $conn->Execute($sql);

?>

<table>
<tr>
<th>Roepnaam</th>
<th>Naam</th>
<th>email</th>
</tr>
<?php while (!$rs->EOF): ?>
<tr>
<td><?= $rs->Fields['Roepnaam']->Value ?></td>
<td><?= $rs->Fields['Naam']->Value ?></td>
<td><?= $rs->Fields['email']->Value ?></td>
</tr>
<?php $rs->MoveNext() ?>
<?php endwhile ?>
</table>

<?php

$rs->Close();
$conn->Close();

?>
--------------------------------end---------------------------------------------------
By: VGR Date: 14/05/2003 21:03:00 English  Type : Comment
basically, you are asking "how do I establish a persistent connection towards Access"

the answer is "no way"

moreover, Access is not a DB, it's a Merdusoft product
By: Trutje Date: 14/05/2003 21:56:00 English  Type : Comment
Thank you for you constructive comment.

I hope you don't mind that I'll wait for some more responces.

Tr,
By: clinresys Date: 14/05/2003 22:00:00 English  Type : Comment
First, have you determined that PHP is actually configured at your ISP? Try a little "Hello World" to see that the webserver is set up.
By: VGR Date: 14/05/2003 22:07:00 English  Type : Answer
sure Trutje :D

it's natural.

Anyway, AFAIK, there is no way to establish a persistent connection using your technique.

And the code you try to convert contains a pconnect() call.

Moreover, I found (experienced) that pconnect() can lead to problems on the Zindoze "platform" and abandoned it.

I suggest you use connect in stead.

BTW, the "code to be changed" is 100% the same as :

$conn = new COM("ADODB.Connection");
$conn->Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=$db");


that you already have.

So I don't get your point in asking this question :D
By: RQuadling Date: 14/05/2003 22:14:00 English  Type : Comment
You may find you get a LOT more results via ODBC. This is supported within PHP.

Richard.
By: clinresys Date: 14/05/2003 22:27:00 English  Type : Comment
1. VGR is right about the "code to be changed" is 100% the same ... in terms of what it is doing.
(and I do share some sentiments about Microlimp)

2. Trutje is getting somewhere with ADODB, let's stay course, for a minute anyway.

3. My sense of it is, that Trutje thinks maybe something is not working for lack of the function to connect to database, which is not the case.

4. So I suggest see if the webserver even knows what PHP is.

By: RQuadling Date: 14/05/2003 23:40:00 English  Type : Comment
Try ...

<?php phpinfo(); ?>

as info.php

This will show all the PHP settings and supported modules IF php is supported by the server.

Richard.
By: VGR Date: 15/05/2003 00:16:00 English  Type : Comment
Dear Richardounet,

[...] PHP is no problem becouse my provider is supporting PHP. [...] I've tested a connection from simple PHP to my Access DB and it works (included as well).




:D
By: Trutje Date: 15/05/2003 05:03:00 English  Type : Comment
Hello RQuadling,

I've used phpinfo(); and it results in a report of a lot of settings. Is this what you like to know?

odbc.allow_persistent = on , on
odbc.check_persistent = on , on

Please let me know if you need to know more.
If ODBC is allowed to be persistent can that solve the problem?

Thanks,

Tr,



By: RQuadling Date: 15/05/2003 19:16:00 English  Type : Comment
What type is PHP support do you have?

If it is a CGI type, then you cannot have persistence as each time the CGI quits everything is lost.

You will need to have the ISAPI (or mod-php I think on a *ix platform), then the server module maintains the persistent connections.

Richard.
By: VGR Date: 15/05/2003 19:47:00 English  Type : Comment
well thought of, Richard
By: clinresys Date: 15/05/2003 21:30:00 English  Type : Comment
Maybe it is me that is confused, re the perceived need to have a persistant open connection to ms access with multiple concurrent web-based query ability being developed.

Multiple concurrent persistent connections is exactly what will grind ms access into its own personal denial of service.
By: VGR Date: 15/05/2003 21:36:00 English  Type : Comment
hence my first (sorry with sorrow :D ) answer :

basically, you are asking "how do I establish a persistent connection towards Access"

the answer is "no way"
By: RQuadling Date: 15/05/2003 21:37:00 English  Type : Comment
Yeah.

So the first thing to do is to get hold of the MSDE and use an SQL engine or use one of the other free sql engines.

Richard.
By: RQuadling Date: 15/05/2003 21:42:00 English  Type : Comment
You can use ODBC to the MSAccess DB and PHP has a persistent connection method for ODBC ...

odbc_pconnect
(PHP 3>= 3.0.6, PHP 4 )

odbc_pconnect -- Open a persistent database connection
Description
resource odbc_pconnect ( string dsn, string user, string password [, int cursor_type])


Returns an ODBC connection id or 0 (FALSE) on error. This function is much like odbc_connect(), except that the connection is not really closed when the script has finished. Future requests for a connection with the same dsn, user, password combination (via odbc_connect() and odbc_pconnect()) can reuse the persistent connection.


Note: Persistent connections have no effect if PHP is used as a CGI program.


For information about the optional cursor_type parameter see the odbc_connect() function. For more information on persistent connections, refer to the PHP FAQ.


Richard.
By: clinresys Date: 15/05/2003 21:45:00 English  Type : Comment
So my question for Trutje is, why do you think you want a persistant connection?
By: Trutje Date: 15/05/2003 21:46:00 English  Type : Comment
RQuadling,

Is this the answer we don't want?

Server API CGI/FastCGI

Thanks,

Tr,
By: RQuadling Date: 15/05/2003 21:58:00 English  Type : Comment
Yep!

As far as I know, there is no persistence for the CGI versions.
By: clinresys Date: 15/05/2003 21:59:00 English  Type : Comment
Personally, if I >>had<< to workup a site on an asp host, my first guess would be that it ran ms servers, and further if I chose to stick with ms access for the backend I'd stick with asp. ms has a way of making things difficult for other-than ms vendors and languages.
By: RQuadling Date: 15/05/2003 22:00:00 English  Type : Comment
DB persistence is normally a good thing for high usage dbs.
By: clinresys Date: 15/05/2003 22:40:00 English  Type : Comment
not when your middle tier is a web server!
By: RQuadling Date: 03/08/2003 03:51:00 English  Type : Comment
Any more info required?

Do register to be able to answer

EContact
browser fav
page generated in 1589.941980 milliseconds

Why Google AdSense ads ?

compteur
 Ranking-Hits PageRank for this page