Home>Article>Backend Development> What should I do if php cannot find the database?

What should I do if php cannot find the database?

藏色散人
藏色散人 Original
2020-08-20 10:39:35 3864browse

The solution to the problem that php cannot find the database: first create a MySQL database named salesinformation; then import the SQL file into the database; and finally run the relevant code.

What should I do if php cannot find the database?

Recommended: "PHP Video Tutorial"

Specific questions:

php - Database not found?

So when I run the register.php file (which contains some basic html form to send to the database), it doesn't seem to be able to find the specific database it's looking for. All files are in the same folder and spelled correctly.

So I will paste the php code into register.php which is the most important html/css code

The database file salesinformation.sql is located in the same folder that contains this code. .

CREATE TABLE IF NOT EXISTS `sales` ( `Username` varchar(25) NOT NULL, `Email` varchar(25) NOT NULL, `Price` int(10) NOT NULL, `Condition` varchar(25) NOT NULL, `RegisterDate` date NOT NULL, PRIMARY KEY (`Username`) );

So this happens when I run xampp "http://localhost/register.php"

Failed to select database Unknown database "salesinformation"

Solution:

The database file salesinformation.sql is located in the same folder that contains this code. .

This does not mean you have a MySQL database.

1) Create a MySQL database named salesinformation.

2) Import the SQL file into the database.

3) Now you have one. Now run your code.

Can you type anything in the terminal (since I can't find any GUI for xampp when running it in ubuntu)? How to create a "MySQL" database? How can I import SQL files into it?

Use the terminal and type CREATE DATABASE salesinformation;

Use shellcd to go to the directory where the salesinformation.sql file is located.

Issue this command mysql -u root -p password salesinformation < salesinformation.sql.

Note: Since I noticed that the root password is empty in your code, you can remove the password item from the above command. If you have a password, enter

there

The above is the detailed content of What should I do if php cannot find 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