How to connect to a database
With most web scripts, any data created when handling a page request is discarded when the script finishes. To be useful, scripts of consequence need persistant data storage. This usually means interacting with a database. X10 offers MySQL and PostgreSQL database servers, and SQLite embedded DB engine. Since SQLite doesn't run as a server, none of the following is needed for it.
Before you can connect to a database server, you need to create a database and database user using cPanel. Once you've done that, any script that needs to connect to your database will use the following information:
- Your cPanel username, followed by an underscore ("_"), followed by the DB username you created in cPanel.
- The password for the DB user you created in cPanel.
- database name
- If using a third party script, you will likely need to set the database name, which is your cPanel username, followed by an underscore ("_"), followed by the DB name you created in cPanel.
- Some third party scripts ask for a port. The X10 DB servers don't use network connections (indeed, network connections aren't allowed on the free servers), so you shouldn't need to set the port. If the script setup forces you to set a port, use 3306 for MySQL or 5432 for PostgreSQL, which are the default values.
Remember, the name of all your DB users and databases begin with your cPanel username followed by an underscore, though tables can have any name you wish (subject to the limitations of the DB server you're using).