Connecting Tech Pros Worldwide Forums | Help | Site Map

Using PHP to pull from MS Access DB

chadlupkes
Guest
 
Posts: n/a
#1: Nov 22 '05
I've been trying to create a simple (I hope) PHP application to send
emails to a membership list. I have yet to successfully connect to my
database to pull the names and email addresses. I'm running XP Pro,
PHP Version 4.3.2, Access 2000. I have created an ODBC System DNS
connection to the database file I want to access, And I get this error:

Warning: SQL error: , SQL state 00000 in SQLConnect in connecttodb.php
on line 2
Whoops! Could Not Connect to ODBC Database!

Here is my code:

<?php
$odbc = odbc_connect ('DFWMembershipDB', '', '') or die('Whoops! Could
Not Connect to ODBC Database!');
?>

I'm a total novice at this, so any help you can provide would be really
appreciated.

Chad Lupkes
Seattle, Washington


steve
Guest
 
Posts: n/a
#2: Nov 22 '05

re: Using PHP to pull from MS Access DB


as you've probably noticed, "whoops!" doesn't get you too far. i think if
you output the actual error, you'd probably be able to figure it out by
yourself. as for those here, "whoops!" means jack-squat.

(dfw = dallas/fort worth? just curious)


"chadlupkes" <chadlupkes@gmail.com> wrote in message
news:1132671012.801427.224270@g43g2000cwa.googlegr oups.com...
| I've been trying to create a simple (I hope) PHP application to send
| emails to a membership list. I have yet to successfully connect to my
| database to pull the names and email addresses. I'm running XP Pro,
| PHP Version 4.3.2, Access 2000. I have created an ODBC System DNS
| connection to the database file I want to access, And I get this error:
|
| Warning: SQL error: , SQL state 00000 in SQLConnect in connecttodb.php
| on line 2
| Whoops! Could Not Connect to ODBC Database!
|
| Here is my code:
|
| <?php
| $odbc = odbc_connect ('DFWMembershipDB', '', '') or die('Whoops! Could
| Not Connect to ODBC Database!');
| ?>
|
| I'm a total novice at this, so any help you can provide would be really
| appreciated.
|
| Chad Lupkes
| Seattle, Washington
|


Kim André Akerĝ
Guest
 
Posts: n/a
#3: Nov 22 '05

re: Using PHP to pull from MS Access DB


steve wrote:
[color=blue]
> as you've probably noticed, "whoops!" doesn't get you too far. i
> think if you output the actual error, you'd probably be able to
> figure it out by yourself. as for those here, "whoops!" means
> jack-squat.[/color]

And "whoops!" isn't a word you want to hear from a sysadmin who's
upgrading a critical system. Especially if followed by "you have
backups of this, right?"

--
Kim André Akerĝ
- kimandre@NOSPAMbetadome.com
(remove NOSPAM to contact me directly)
steve
Guest
 
Posts: n/a
#4: Nov 22 '05

re: Using PHP to pull from MS Access DB



"Kim André Akerĝ" <kimandre@NOSPAMbetadome.com> wrote in message
news:3ugsluF118j87U1@individual.net...

| And "whoops!" isn't a word you want to hear from a sysadmin who's
| upgrading a critical system. Especially if followed by "you have
| backups of this, right?"

roflmao


chadlupkes
Guest
 
Posts: n/a
#5: Nov 23 '05

re: Using PHP to pull from MS Access DB


So, saying I'm a total novice didn't make it clear enough, eh?

How do I output the actual error?

(DFW - Democracy for Washington)

steve
Guest
 
Posts: n/a
#6: Nov 23 '05

re: Using PHP to pull from MS Access DB


novice implies ignorance and not stupidity. while there is nothing wrong
with the former, the latter i find is hard to excuse.

i bet if you were to google "php odbc error help", you'd find your answer.
or if you went to php.net and searched for "odbc error", you'd likewise come
up with odbc_error() and odbc_errormsg()

searching for and finding help is a methodology employed by anyone with a
problem. as we all have them, none are novices. asking for help with novice
questions when the answer(s) are so pervasive, prevelent, and otherwise
readily available is...well...stupid. what's worse is doing so and then
being smug at the same time...eh! but, perhaps i just mis-read your tone in
this media.

(there is no d in w, but thanks for curing my curiosity)


"chadlupkes" <chadlupkes@gmail.com> wrote in message
news:1132713300.457168.83110@f14g2000cwb.googlegro ups.com...
| So, saying I'm a total novice didn't make it clear enough, eh?
|
| How do I output the actual error?
|
| (DFW - Democracy for Washington)
|


chadlupkes
Guest
 
Posts: n/a
#7: Nov 23 '05

re: Using PHP to pull from MS Access DB


You mis-read. I was smiling.

I've been looking through the thousands of results from searches like
the ones you recommended, and I've been trying a lot of what I find.
Every step just leads to more and more questions that I can't find
answers to. So, I appreciate the direct help.

I'm trying to create a very simple script that will pull email
addresses from an existing database and export them with message
content to my local smtp server. To do that, I've read that I need to
set up an System DNS to the database file, which I've done according to
all the directions I can find. Now I'm trying to test the connection.

The errors I'm getting are leading me into another maze of search
results, and they all seem to be for people who have a basic
understanding of what is happening. Or the tutorials assume that
everything works just as they describe. So when things don't work, I
ask for help.

Chad

chadlupkes
Guest
 
Posts: n/a
#8: Nov 23 '05

re: Using PHP to pull from MS Access DB


Here's the latest update:

<?php
$connectionstring = odbc_connect("DFWDB", "chad", "dfw");
if (odbc_error())
{
echo odbc_errormsg($connectionstring);
}
odbc_close($connectionstring);
?>

This is what comes out:

Warning: SQL error: [Microsoft][ODBC Microsoft Access Driver] The
Microsoft Jet database engine cannot open the file '(unknown)'. It is
already opened exclusively by another user, or you need permission to
view its data., SQL state S1000 in SQLConnect in
C:\Inetpub\wwwroot\politics\DFW\connecttodb.php on line 2

Warning: odbc_errormsg(): supplied argument is not a valid ODBC-Link
resource in C:\Inetpub\wwwroot\politics\DFW\connecttodb.php on line 5

Warning: odbc_close(): supplied argument is not a valid ODBC-Link
resource in C:\Inetpub\wwwroot\politics\DFW\connecttodb.php on line 7

--
This doesn't make sense. I don't have any other connections open to
the database, although I can't get the ODBC logfile to work to check.
I haven't set any restrictions on access, since this is all on my local
machine, although I'm not sure what permissions I need to set. And the
odbc_ functions just seem to fail.

I'm really lost.

steve
Guest
 
Posts: n/a
#9: Nov 23 '05

re: Using PHP to pull from MS Access DB


ok, smiling one. ;^)

usually, one db error will cascade multiple errors in php since most db
functions rely on a resource provided by another db function. anyway...what
you've got is a failure to connect and yet you continue to try to use other
functions that rely on that connection which in turn throws errors number 2
and 3.

your literal problem is that access (shitty as it is) stores its data in a
file. when php tries to open that db/file, your pc tries to access it as
IUSR_<computer name here>...that is, if you're using IIS (incredibly
insecure server). you must allow read/write permissions for that user on the
directory in which your mdb resides.

btw, you do *NOT* need a dsn to connect to the db, as a standard odbc
connection string in the form of:

"Driver={Microsoft Access Driver
(*.mdb)};Dbq=C:\mydatabase.mdb;Uid=Admin;Pwd=;"

will work just fine.

(look at http://www.connectionstrings.com/ for most common connection
strings)


does that explain things to your satisfaction?


| Warning: SQL error: [Microsoft][ODBC Microsoft Access Driver] The
| Microsoft Jet database engine cannot open the file '(unknown)'. It is
| already opened exclusively by another user, or you need permission to
| view its data., SQL state S1000 in SQLConnect in
| C:\Inetpub\wwwroot\politics\DFW\connecttodb.php on line 2
|
| Warning: odbc_errormsg(): supplied argument is not a valid ODBC-Link
| resource in C:\Inetpub\wwwroot\politics\DFW\connecttodb.php on line 5
|
| Warning: odbc_close(): supplied argument is not a valid ODBC-Link
| resource in C:\Inetpub\wwwroot\politics\DFW\connecttodb.php on line 7
|
| --
| This doesn't make sense. I don't have any other connections open to
| the database, although I can't get the ODBC logfile to work to check.
| I haven't set any restrictions on access, since this is all on my local
| machine, although I'm not sure what permissions I need to set. And the
| odbc_ functions just seem to fail.
|
| I'm really lost.
|


chadlupkes
Guest
 
Posts: n/a
#10: Nov 24 '05

re: Using PHP to pull from MS Access DB


Well, well. Yes, that did it. And none of the tutorials I had found
mentioned a possible permissions problem, so I hadn't even considered
it. You saved the day.

Now I just have to figure out SQL...

Thanks!!

Chad

chadlupkes
Guest
 
Posts: n/a
#11: Nov 24 '05

re: Using PHP to pull from MS Access DB


Ok, looks like I do have one more question. The page works, but only
when the file is closed. Is it possible to set the permissions such
that I can use the database through the Access interface at the same
time I'm doing SQL queries through the web server?

Chad

steve
Guest
 
Posts: n/a
#12: Nov 24 '05

re: Using PHP to pull from MS Access DB


that's nothing to do with php or file permissions...you have to open the db
in access and set its options to not open exclusively. check access' help
files for that...too many moons have gone by since i've messed around with
it.

glad you've gotten over your first hurdle.


"chadlupkes" <chadlupkes@gmail.com> wrote in message
news:1132857574.741007.163060@z14g2000cwz.googlegr oups.com...
| Ok, looks like I do have one more question. The page works, but only
| when the file is closed. Is it possible to set the permissions such
| that I can use the database through the Access interface at the same
| time I'm doing SQL queries through the web server?
|
| Chad
|


Adam
Guest
 
Posts: n/a
#13: Mar 7 '06

re: Using PHP to pull from MS Access DB


On Wed, 23 Nov 2005 09:23:08 -0600, steve wrote:
[color=blue]
>your literal problem is that access (shitty as it is) stores its data in a
>file.[/color]

Steve - it's not *that* bad ;-) - for an average sized application.
I've used it with ColdFusion and PHP on pretty busy sites. The usual
networking gotchas in Access (locking) are avoided as PHP (or CF)
handles/buffers the requests.

Sometimes, the client insists on keeping the DB in its native format
(and maybe swaps the whole file over periodically). It can end up
quicker.

The only real downside I find is the weird Access time/date format.

Adam.
Closed Thread


Similar PHP bytes