prepare("INSERT INTO project.users ( userName, userEmail) VALUES (?,?)");"."/> prepare("INSERT INTO project.users ( userName, userEmail) VALUES (?,?)");".">

Home >Backend Development >PHP Problem >What to do if php PDO fails to import the database

What to do if php PDO fails to import the database

藏色散人
藏色散人Original
2022-10-28 10:11:421551browse

php PDO failed to import the database solution: 1. Modify the connection statement to "'mysql:host=localhost;dbname=project'"; 2. Re-execute the query statement to "$dbh->prepare( "INSERT INTO project.users (userName, userEmail) VALUES (?,?)");" That's it.

What to do if php PDO fails to import the database

The operating environment of this tutorial: Windows 7 system, PHP version 8.1, Dell G3 computer.

php What should I do if PDO fails to import the database?

An error message is displayed indicating that you have connected to the database fine, but the project database has not been selected yet.

To be sure it's trying to correct with the correct DSN, I would try changing the connection string to contain the value directly instead of a variable, ie:

'mysql:host=localhost;dbname=project'

This shouldn't make a difference, but is worth checking .

If that doesn't work, and since you seem to be able to connect to MySQL,

The workaround might be to include the database name as part of the query.

So your query above will become:

$query=$dbh->prepare("INSERT INTO project.users (userName, userEmail) VALUES (?,?)");

The above is the detailed content of What to do if php PDO fails to import the database. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn