Connect to MySQL Databases Using PHP (Code Examples)

For Linux and Windows Web Hosting packages

Learn how to view code examples for connecting to your MySQL database. 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.

  • Log in to 1&1 IONOS and select Hosting.
  • Click Manage in the MySQL Database section.
  • From the Actions menu, click Sample Code (PHP).
  • Click on the tabs to view PHP code examples for the MySQL extensions MySQL, MySQLi and PDO.
  • Copy and paste the code into your PHP script.
  • Enter your database password where indicated in the code.
  • Now you can upload the script to your web space and test it.

Please Note:

  • For security reasons, the database server can only be reached from servers in the 1&1 IONOS network. This means that the connection will not work if you run it on your local PC.
  • If you no longer know your MySQL password, you can Set a New MySQL Database Password.