How to connect PHP with Microsoft Access database

后端 未结 6 630
感情败类
感情败类 2020-12-02 19:23

I am currently faced with a new challenge to develop a site using Microsoft Access as the primary database instead of mysql. I have not used MS Access before and I would lik

6条回答
  •  [愿得一人]
    2020-12-02 19:55

    If you are just getting started with a new project then I would suggest that you use PDO instead of the old odbc_exec() approach. Here is a simple example:

    setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    
    $sql = 
            "SELECT AgentName FROM Agents " .
            "WHERE ID < ? AND AgentName <> ?";
    $sth = $dbh->prepare($sql);
    
    // query parameter value(s)
    $params = array(
            5,
            'Homer'
            );
    
    $sth->execute($params);
    
    while ($row = $sth->fetch()) {
        echo $row['AgentName'] . "\r\n";
    }
    

    NOTE: The above approach is sufficient if you do not need to support Unicode characters above U+00FF. If you do need to support such characters then neither PDO_ODBC nor the old odbc_ functions will work; you'll need to use the solution described in this answer.

提交回复
热议问题