How can I connect Railway in a PHP file?
I normally used MySQL on localhost, but I decided to try using online. I made my connections through MySQLi, but I am not able to connect Railway. Can someone help me?
12 Replies
Project ID:
N/A
You would want to add the MySQL environment variables to your service. Then use the PHP
getenv()
function to read them in to your connection string
Depending on how you are connecting, you will either only need the URI, or you might need to add them all
Are you using a framework or vanilla PHPvanilla
I made my connections like that
show us a screenshot of your service variables please
What is it? I'm still quite a beginner, I only know the basics of the basics, how to turn on localhost and make the queries, add, remove, etc..
your railway service variables
You also need to use the port variable
MySQL on Railway does not use the standard 3306 port, so it must be specified in your connection
how i do this?
Like this
You need to add those through references to your PHP service
Where your code lives on railway, you will see the “Add New Variable” button. You can select the “Reference Variable” and select each of them one at a time
The only one you don’t need to add to your PHP service is the
MYSQL_URL