SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Hybrid View

  1. #1
    SitePoint Enthusiast einstien_ii's Avatar
    Join Date
    Jan 2001
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey! there,

    Months ago, I learned to use mySQL and PHP from Kevin's Tutorials and now I have mastered it to an extent. However, I really don't know how to connect to a MS Access Database from a PHP Script and then run a SQL Query.

    Can anyone help me with the syntax to connect to a MS DSN ?

    Also, I would like to know if there are any special problems to note while using MS Access with PHP unlike mySQL with PHP.

    I am really looking forward to your replies, got a site to work upon!


    Krishna Narayanan
    einstien_ii@zeenext.com
    http://www.talofians.net


  2. #2
    SitePoint Zealot HotDog's Avatar
    Join Date
    May 2000
    Location
    Salt Lake City, UT
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Finally...something I know a little bit about!!

    The very first thing you need to know is that MS ACCESS connects to php through odbc, so you need odbc installed on your computer. To check this go to your CONTROL PANEL. In WIN2000 you'll need to go into Administrative Tools and you should see an Icon called DATA SOURCES (ODBC). I'm not sure, but in WIN 9X your ODBC directory should be right in the CONTROL PANEL. At any rate, you should find it in the CONTROL PANEL somewhere.

    If you don't find it there, then you don't have it installed. For now I'll ASSUME you have it installed already.

    Next, open up your ODBC directory. You should see several tabs at the top, 2 of which should say "USER DNS" and " SYSTEM DNS". This is where you setup your link to the ACCESS database. The USER DNS setups up the database so only YOU can access it from THIS machine. The SYSTEM DNS allows all users on THIS machine plus all users in a MS NETWORK to access the database. Choose which way you want to setup the database (only you can access it or everyone can access it). FILE DNS allows you to connect to another database not installed on your computer. Again...I'm ASSUMING you have the DB installed on THIS machine.

    After choosing which DNS you want, click the "ADD" button. This will open up a window that will allow you to choose which odbc driver to use. Choose the one that says "Microsoft Access Driver(*.mdb). Click "OK". This then opens up a window of linking your db. In "Data Source Name" type any old name you want to refere to the database from odbc. You can type a disciption if you like.

    In the next section "Database" click on "Select" and select you database. Click "ok" then "ok". Your all done. You are now ready to access your ACCESS database from php using the odbc database call. For more information on that go to
    http://www.php.net/manual/en/ref.odbc.php.

    Hope this helps out.
    <Edited by HotDog on 01-31-2001 at 07:47 PM>
    Joe Eliason
    Just a dog learnin' PHP from cat.

  3. #3
    SitePoint Zealot HotDog's Avatar
    Join Date
    May 2000
    Location
    Salt Lake City, UT
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by einstien_ii

    Also, I would like to know if there are any special problems to note while using MS Access with PHP unlike mySQL with PHP.
    The biggest limiting factor I've found is the SQL in mySQL will allow you to do somethings that you can't with other databases, ie MS ACCESS. For more on this read my post at http://www.sitepointforums.com/showt...threadid=15284

    The only other thing is you have to learn a new way to call the database in PHP using the odbc call instead of mysql. But I picked both up fairly quickly, so you shouldn't have any problem.
    Joe Eliason
    Just a dog learnin' PHP from cat.

  4. #4
    SitePoint Zealot HotDog's Avatar
    Join Date
    May 2000
    Location
    Salt Lake City, UT
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    One more thing then I'll shut up...You can also install odbc drivers for MySQL so you can link tables into ACCESS as well. This way you can continue using MySQL in PHP but view and work with the data in ACCESS. The down side to doing it this way is you are limited to only working with the data in the linked tables from the MySQL database. You will not be able to manipulate the tables themselves any. You will still need to do that directly in MySQL. But the upside is you have the tables available in ACCESS for writing reports or forms from the MySQL data, plus you still have all the advantages that MySQL has in PHP since in PHP you call the MySQL database instead of the access database.

    It's just another option.

    If you would like more information on this, just let me know.
    Joe Eliason
    Just a dog learnin' PHP from cat.

  5. #5
    SitePoint Enthusiast einstien_ii's Avatar
    Join Date
    Jan 2001
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanx for the info, HotDog.

    Actualy I'm pretty convenient with both mySQL and MS Access. Its PHP that I am new to. So, I was looking forward to know, how to connect to the Database via an ODBC!

    For instance, we connect to mySQL simply using :

    host,user,pass

    instead for MS Access, we will have to specify a DSN and then so on .....

    So thats the code I am looking forward to!

    Regs,

    Krishna Narayanan
    einstien_ii@zeenext.com
    http://www.talofians.net


  6. #6
    SitePoint Zealot HotDog's Avatar
    Join Date
    May 2000
    Location
    Salt Lake City, UT
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK...so I lied. One more thing...

    There is a EXCELENT resource for ACCESS SQL at http://msdn.microsoft.com/library/techart/acfundsql.htm

    There are 3 web pages dedicated to ACCESS Jet SQL. This above link is to the Fundamentals page. At the end of that page there are links to Internediate and Advanced Jet SQL. Great resource.

    One last thing. In Access, you can access a query from ACCESS the same as a table, which is a HUGE plus since you can create all your queries in the database and access the results instead of creating the query in PHP from the SQL. And since ACCESS lets you access the SQL code, you can always make a query of what you want, access the SQL code and then paste it into your PHP code as well.
    Joe Eliason
    Just a dog learnin' PHP from cat.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •