Connecting to PHP on MySQL Databases (Code Examples)

Please Note:

The text on this page was translated by translation software. A revised version from our editors will be available soon.

For Web Hosting Linux and Windows packages

Do you program yourself or do you need the code for the configuration file of your web application? As a 1&1 IONOS customer, you can simply download the code required to connect to your MySQL database in the form of code examples from the 1&1 IONOS. This code already contains most of the access data - all you need to do is enter your database password and you are ready to go.


You have created a MySQL database


Step 1

Log in to 1&1 IONOS and select the relevant contract.

Step 2

Select MySQL Database from the left menu bar under My Products.

Step 3

Choose Actions > Code Samples (PHP).

Step 4

Click on each tab to view PHP code examples for the MySQL extensions MySQL, MySQLi and PDO.

Step 5

Copy and paste the code into your PHP script.

Step 6

Enter your database password at the position indicated in the code.

Step 7

Now you can upload the script to your web space and test it.


  • For security reasons, the database server can only be reached in the 1&1 IONOS network. This means that the script does not work if you run it on your local PC, for example.
  • If you no longer know your MySQL password, simply enter a new one in 1&1 IONOS.