Home >Operation and Maintenance >phpstudy >How to configure the database in phpstudy
Configuring the database in PHPstudy
PHPstudy is an integrated development environment that integrates PHP, MySQL, and Apache. Configuring the database in PHPstudy is very simple, here are the detailed steps:
1. Start PHPstudy
Double-click the desktop icon or find and start PHPstudy in the start menu.
2. Enable MySQL Service
In the PHPstudy interface, click the "MySQL" tab, and then make sure "MySQL Service" is enabled.
3. Create a database
Click the "Databases" tab, and then click the "Add Database" button. Enter a name for the new database in the Database Name field and click OK.
4. Create a database user
Click the "Users" tab, and then click the "Add User" button. Enter your new username and password in the Username and Password fields. Make sure the Grant all permissions checkbox is selected and click OK.
5. Grant the user permissions on the database
Go back to the "Databases" tab and select the new database you created. Then, in the Users tab, check the new user's checkbox in the Account column and make sure it says "All permissions" in the Granted permissions column.
6. Configure PHP to connect to the database
Find the php.ini
file in the root directory of PHPstudy and open it with a text editor. Find the following line:
<code>; MySQL 配置选项 ; mysql.default_socket = mysql.default_host = 127.0.0.1 mysql.default_user = root mysql.default_password = mysql.default_port = 3306</code>
Replace the following with the following:
<code>mysql.default_socket = mysql.default_host = 127.0.0.1 mysql.default_user = 新的用户名 mysql.default_password = 新的密码 mysql.default_port = 3306</code>
Save and close the php.ini
file.
7. Test the connection
Use the following code in your PHP code to test the connection to the database:
<code class="php"><?php $servername = "127.0.0.1"; $username = 新的用户名; $password = 新的密码; $dbname = 新的数据库名; // 创建连接 $conn = new mysqli($servername, $username, $password, $dbname); // 检查连接 if ($conn->connect_error) { die("连接失败: " . $conn->connect_error); } echo "连接成功"; ?></code>
If all goes well, you should You will see a "Connection successful" message.
The above is the detailed content of How to configure the database in phpstudy. For more information, please follow other related articles on the PHP Chinese website!