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
Percy
Percy16mo ago
Project ID: N/A
MantisInABox
MantisInABox16mo ago
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 PHP
andrealves8406
andrealves840616mo ago
vanilla
andrealves8406
andrealves840616mo ago
I made my connections like that
Brody
Brody16mo ago
show us a screenshot of your service variables please
andrealves8406
andrealves840616mo ago
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..
Brody
Brody16mo ago
your railway service variables
MantisInABox
MantisInABox16mo ago
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
andrealves8406
andrealves840616mo ago
how i do this?
MantisInABox
MantisInABox16mo ago
Like this
andrealves8406
andrealves840616mo ago
MantisInABox
MantisInABox16mo ago
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
Want results from more Discord servers?
Add your server