the answer to your question is not related to the database. it's only about php programming.
you should build 2 tables.
the first one should only contain for each railway station : an id, the name, and other eventual information which will not affect the algorithm
the second one should contain the connections between stations like this(sample row structure) :
id_number(will be used for index)
id for station 1
id for station 2
where station 1 & 2 are connected one to other
when calculating the shortest way you will have to load from the first database the number of railway stations and with it build the connection matrix from the second database. it will look like this :
r1 r2 r3 r4 r5
r1 0 1 0 1 0
r2 1 0 0 1 0
r3 0 0 0 0 1
r4 1 1 0 0 0
r5 0 0 1 0 0
where 0 is for no connection between stations and 1 for existing connection
i don't remember very much the djikstra algorithm but i hope this will help you.