Page 1 of 2 12 LastLast
Results 1 to 15 of 21
  1. #1
    Join Date
    Oct 2007
    Posts
    27

    Question Unanswered: MS Access & PHP Question

    I need to create a form for users to enter in information. The information they need to enter is:

    ~ Name
    ~ Date
    ~ Miles
    ~ Activity

    In my MS Access database, the name is set up in a table named name analyzer and all of the information needs to be entered into a table named activity_log. I want it to verify that the name is in the name analyer table, but if it's not, send an error message to the user.

    Okay so here is my question, can I do this with PHP? I've worked with PHP & MySQL before but never with Access.

    If it's possible can someone direct me to a tutorial or something so I can figure out how to do this? I need to have this page done by tomorrow and I'm clueless!

    Thanks!

  2. #2
    Join Date
    Jan 2005
    Posts
    362

    Php

    If you have a server (Microsoft based-I am not sure that ms Access runs at others like Linux etc) running php you can.And that will run via web browser .
    You may read this and this .

  3. #3
    Join Date
    Mar 2007
    Location
    636f6d7075746572
    Posts
    770
    You can connect to MSAccess in PHP using ODBC.
    See http://uk2.php.net/manual/en/function.odbc-connect.php to get yourself started. You'll need to create a DSN connection string in windows before you can utilise it however.

    After that it's pretty much the same as using MySQL in PHP, and you can perform SQL statements as you would any other database.

  4. #4
    Join Date
    Mar 2007
    Location
    636f6d7075746572
    Posts
    770
    When you talk about "verify that the name is in the name analyer table" do you mean that the user is entering some login information and if those login details don't exist then you have to output a message saying such? Or are you talking about some other sort of input and verification?

  5. #5
    Join Date
    Oct 2007
    Posts
    27
    Quote Originally Posted by aschk
    When you talk about "verify that the name is in the name analyer table" do you mean that the user is entering some login information and if those login details don't exist then you have to output a message saying such? Or are you talking about some other sort of input and verification?
    Yes.

    Thank you all for your help! I greatly appreciate it!!

  6. #6
    Join Date
    Oct 2007
    Posts
    27
    Okay so I have another stupid question. For the ODBC connection, do I need to set that up on the server this will be located on?

  7. #7
    Join Date
    Jan 2005
    Posts
    362
    What version of MS Access do you have.
    If you have 2007 for the connection sting look at this else this.
    Connectionstrings
    ODBC DSN-less Connections
    DSN less connections don't require creation of system level DSNs
    for connecting to databases and provide an alternative to DSNs.
    Instead of using a DSN to connect to a database,
    the developer specifies the necessary information right in the application.
    With a DSN-less connection the developer is free to use connection standards
    other than ODBC, such as OLE DB.
    DSN-less connections should be used when you do not have access to the server to register DSNs yourself.
    For Microsoft Access, the following connection string is used to create DSN-less connections:
    Driver={Microsoft Access Driver (*.mdb)}; DBQ=c:\path\to\database.mdb
    Last edited by dimis2500; 10-24-07 at 10:09.

  8. #8
    Join Date
    Oct 2007
    Posts
    27
    Quote Originally Posted by dimis2500
    What version of MS Access do you have.
    If you have 2007 for the connection sting look at this else this
    I have 2003.

    So do i put this in my code?

    Code:
    Driver={Microsoft Access Driver (*.mdb)};Dbq=C:\mydatabase.mdb;
    with my db information of course though..
    Last edited by mstng07; 10-24-07 at 10:08.

  9. #9
    Join Date
    Jan 2005
    Posts
    362
    Code:
    odbc_connect
     ( string $dsn, string $user, string $password [, int $cursor_type] )
    As I understand at
    Code:
     $dsn
    .

  10. #10
    Join Date
    Oct 2007
    Posts
    27
    I'm just trying to test this...

    Code:
    <?
    $conn = new COM("ADODB.Connection") or die("Cannot start ADO"); 
    
    // Microsoft Access connection string.
    $conn->Open("Provider=Microsoft,.Jet.OLEDB.4.0; Data Source=F:\\Inetpub\\wwwroot\\EmployeeWellnessProgram\\Copy of HR Employee Wellness Program.mdb");
    
    // SQL statement to build recordset.
    $users = $conn->Execute("SELECT * FROM [analyzer query]");
    
    // Display all the values in the records set
    while (!$users->EOF) {
        $fv = $users->Fields("[Employee ID]");
        echo "Value: ".$fv->value."<br>\n";
        $users->MoveNext();
    } 
    $users->Close();
    ?>
    and i get these errors...
    Warning: (null)(): Invoke() failed: Exception occurred. Source: ADODB.Connection Description: Provider cannot be found. It may not be properly installed. in F:\InetPub\wwwroot\EmployeeWellnessProgram\TestDis play.php on line 5

    Warning: (null)(): Invoke() failed: Exception occurred. Source: ADODB.Connection Description: Operation is not allowed when the object is closed. in F:\InetPub\wwwroot\EmployeeWellnessProgram\TestDis play.php on line 8

    Fatal error: Call to a member function on a non-object in F:\InetPub\wwwroot\EmployeeWellnessProgram\TestDis play.php on line 13

  11. #11
    Join Date
    Jan 2005
    Posts
    362
    Maybe this
    Code:
    Driver={Microsoft Access Driver (*.mdb)};Dbq=C:\mydatabase.mdb;
    And I thing that is better not to have spaces the strings like names of files.
    Strings.
    Last edited by dimis2500; 10-24-07 at 10:58.

  12. #12
    Join Date
    Oct 2007
    Posts
    27
    yeah i know it's better but i didn't create the database. sure as heck would be easier without the spaces because i don't know if i'm doing it right

  13. #13
    Join Date
    Jan 2005
    Posts
    362

    Spaces

    So you can give the database a name without spaces, just rename it.
    The script is ok now?
    Dimis

  14. #14
    Join Date
    Mar 2007
    Location
    636f6d7075746572
    Posts
    770
    Ah right, you're using COM objects.
    This is ONLY available on Windows and relies on the COM being installed.
    Don't use COM, use odbc_connect as it's built into PHP by default (in most cases). It's easier to use, because it works pretty much the same way all the mysql_... functions do.

  15. #15
    Join Date
    Mar 2007
    Location
    636f6d7075746572
    Posts
    770
    See http://www.w3schools.com/php/php_db_odbc.asp for some help.

    A code example might look like this :
    Code:
    <html>
    <body>
    
    <?php
    $dsn_str = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=F:\Inetpub\wwwroot\EmployeeWellnessProgram\Copy of HR Employee Wellness Program.mdb;";
    
    // Connect to DSN
    $conn=odbc_connect($conn_str,'MyDBUser','MyDbPassword');
    
    // If connection failed
    if (!$conn)
      {exit("Connection Failed: " . $conn);}
    
    // Query string
    $sql="SELECT * FROM table_name";
    
    // Execute Query
    $rs=odbc_exec($conn,$sql);
    
    // On query fail
    if (!$rs)
      {exit("Error in SQL");}
    
    // Set up table
    echo "<table><tr>";
    echo "<th>Column1</th>";
    echo "<th>Column2</th></tr>";
    
    // Loop recordset
    while (odbc_fetch_row($rs))
    {
      $col1=odbc_result($rs,"Column1");
      $col2=odbc_result($rs,"Column2");
      echo "<tr><td>$col1</td>";
      echo "<td>$col2</td></tr>";
    }
    
    // Close connection
    odbc_close($conn);
    
    // Close table
    echo "</table>";
    ?>
    
    </body>
    </html>

Posting Permissions

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