


PHP connection to Access database errors and solutions_PHP tutorial
There are generally two common ways for php+access to connect to the database.
Recommended code
It should be noted that php uses realpath to obtain the path
$connstr="DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" . realpath("data.mdb");
$connid=odbc_connect($connstr,"","",SQL_CUR_USE_ODBC);
$issuetime=date("Y-m-d H:i:s");
$sql="insert into test values("","",...)";
$result=odbc_exec($connid,$sql);
if($result) echo "successful";
else echo "failed";
?>
Part 2:
//Create ADO connection
$conn = @new COM("ADODB.Connection") or die ("ADO connection failed! ");
$connstr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" . realpath("temp/TempData.mdb");
$conn->Open($connstr );
//Create record set query
$rs = @new COM("ADODB.RecordSet");
$rs->Open("select * from blog_Content",$conn ,1,3);
echo $rs->Fields["log_Title"]->Value; //Output log_Title field
echo "
";
$rs- >Movenext(); //Move the record set pointer down
echo $rs->Fields["log_Title"]->Value;
$rs->close();
? >
The following is a supplement
1. Create an odbc driver and then use PHP’s odbc_connect() function to connect.
For example:
$connstr=DRIVER={Microsoft Access Driver (*.mdb )}; DBQ=".$db;
$connid=odbc_connect($connstr,"username","password",SQL_CUR_USE_ODBC);
2. Use oledb to connect, and then call the open method to open
, such as:
$conn=new com("ADODB.connection");
$connstr ="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=".$db;
$conn->Open($connstr);
However, no matter how I connect these two methods, there are errors. When I looked for information on the Internet, some said that Everyone permission was not granted, and some said that the drivers of access97 and access2000 were different (that is, the database was built in 2000 and was used for reading. The driver is 97.).
After repeated testing, it turned out to be caused by the path of the database. In the past, when developing asp, I used to write the address of the database as a relative path, and then use the server.mappath() function to obtain its absolute path.
This habit was also continued when developing PHP, using realpath plus the relative path of the database to obtain the address of the database. For example: $db=realpath("../db.mdb");
However, the include function of asp and the include function of php seem to process included files in different ways, which causes "common error cannot open the registry keyword" when php includes the conn.php file in different directories to connect to the database.
or Uncaught exception 'com_exception' with message 'Source: ProviderDescription: Authentication failed. ' error.
Now I will sort out the error messages and solutions and post them to everyone. I hope other friends who encounter this situation will not be as depressed as me
Error 1
php connection access database FAQ
Warning: odbc_connect() [
function.odbc-connect
] : SQL error: [Microsoft][ODBC Microsoft Access Driver]Common error Cannot open registry key 'Temporary (volatile) Jet DSN for process 0xdd0 Thread 0xcb8 DBC 0x14bd024 Jet'. , SQL state S1000 in SQLConnect in E:wwwrootphperz.comphpwebconn.php on line 8
If this error occurs, it proves that you are using the odbc access driver, which is the first method of connecting to the database mentioned above $connstr=DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=".$db ;
And the file you are currently accessing is not in the same directory as your conn.php database connection file. The relative path used when including conn.php, such as include("../conn.php"), because PHP handles include The files in the function are different from those in asp,
Caused an error in the database path,
Solution:
1. Check the path of your database to see if it is obtained by using the realpath() function plus a relative path.
For example: $db=realpath("../db.mdb");
If so, please use another method to obtain the database address, such as: $_SERVER['DOCUMENT_ROOT'] to obtain the root of your website Project, add the address of the database
Example: $db=$_SERVER['DOCUMENT_ROOT']."db.mdb";
2, check the permissions and give him Everyone permission
3. Change the connection method. Microsoft's odbc driver has some unstable bugs, which may cause such errors. It is said that Microsoft itself has given up support for the odbc data source connection method and recommends users to use the oledb method. The connection string should be changed to the following:
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=".$db;
Error 2:
Fatal error: Uncaught exception 'com_exception' with message 'Source: ProviderDescription: Authentication failed. ' in E:wwwrootphperz.comphpwebconn.php:7 Stack trace: #0 E:wwwrootphperz.comphpwebconn.php(7): com->Open('Provider=Micros...') #1 ...... .........
This error means that you are using oledb to connect to the database, and it is also caused by the path of the database.
The solution is the same as above, use $_SERVER['DOCUMENT_ROOT']."db.mdb"; method to obtain the database address
Error 3:
Warning: odbc_connect() [
function.odbc-connect
] : SQL error: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified, SQL state IM002 in SQLConnect in E:wwwrootphperz.comphpwebconn.php on line 8
For databases connected using the odbc driver, the error may be caused by your connection string being written incorrectly. The complete connection string should be:
$db=$_SERVER['DOCUMENT_ROOT']."db.mdb";
$connstr="Driver={Microsoft Access Driver (*.mdb)};Dbq=$db;Uid=Admin;Pwd=pass";
$connid=odbc_connect($connstr,"admin","pass ",SQL_CUR_USE_ODBC) or die("Database opening failed! Please contact the administrator");
If your database does not have a password, the above Uid and Pwd can be omitted
$connstr="Driver={Microsoft Access Driver (*.mdb)};Dbq =$db";
$connid=odbc_connect($connstr,"","",SQL_CUR_USE_ODBC) or die("Database opening failed! Please contact the administrator");
Error 4:
Fatal error: Uncaught exception 'com_exception' with message 'Source: ADODB.ConnectionDescription: Provider not found. The program may not be installed correctly. ' in......................
oledb connection method, the error reason is the same as above, the complete connection string should be:
$db=$_SERVER['DOCUMENT_ROOT']."db.mdb";
$conn=new com("ADODB.connection");
$connstr="Provider=Microsoaf.Jet.OLEDB.4.0;Data Source=".$db;
$conn->Open( $connstr);

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

DeepSeek cannot convert files directly to PDF. Depending on the file type, you can use different methods: Common documents (Word, Excel, PowerPoint): Use Microsoft Office, LibreOffice and other software to export as PDF. Image: Save as PDF using image viewer or image processing software. Web pages: Use the browser's "Print into PDF" function or the dedicated web page to PDF tool. Uncommon formats: Find the right converter and convert it to PDF. It is crucial to choose the right tools and develop a plan based on the actual situation.

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.
