I have two servers and one of them have mysql db and one doesnt so is it possible to use mysql db in my other server while hosting my website on another. also if there is how would you do it with php.

Recommended Answers

All 8 Replies

I have two servers and one of them have mysql db and one doesnt so is it possible to use mysql db in my other server while hosting my website on another. also if there is how would you do it with php.

Just set the host parameter of the mysql_connect function to the IP address of the other server. You'll also need to open the MySQL port (3306) on the other server if it's closed

well could you give me a example as how it would be done,
This how i set up my query:

$connection = mysql_connect(DB_HOST, DB_USER, DB_PASS)
   or die("Query failed : " . mysql_error());
$db = mysql_select_db(DB_NAME, $connection)
   or die("Query failed : " . mysql_error());

what will I have to change in this to make it work.

$connection = mysql_connect(IP_ADDRESS_OF_DATABASE_SERVER:PORT_YOU_SET_MYSQL_TO_LISTEN_ON, DB_USER, DB_PASS)
   or die("Query failed : " . mysql_error());
$db = mysql_select_db(DB_NAME, $connection)
   or die("Query failed : " . mysql_error());

I shouldn't be telling a programmer what 'host' means. Seriously; learn to walk before you run.

Try reading this

Thanks a lot, that helps.
I am still learning php and my sql, heck I am still in high school and taught everything myself so I know I will make mistakes and not know many things. Also I need people who tell me i dont know this and that because that is what motivates me to learn:lol: ...
Thanks again

Thanks a lot, that helps.
I am still learning php and my sql, heck I am still in high school and taught everything myself so I know I will make mistakes and not know many things. Also I need people who tell me i dont know this and that because that is what motivates me to learn:lol: ...
Thanks again

No problem. I when you said 'i have two servers' I assumed you were talking about work.

If you're starting I recommend this. Also, the php docs are always going to be useful as are the MySQL (and no doubt Apache) ones.

Don't restrict yourself to just learning PHP stuff. You need to know things like the TCP/IP protocol and telecommunication to understand what HOSTS and PORTS and IP's are and the Server/Client model yadda yadda...

I've been reading for 7 years and there's still stuff I struggle with even now especially security and permissions yuck ! To get where I have I've had to dedicate a little of every day to reading online tutorials / developer blogs / forums and heaps of books (which you have to read more than once and then some) But I am living proof you can do it, I never did a Degree course in computing (I did a business course)

One thing I have learnt is that learning a programming language is a cinch compared to actually using it in anger.

Ohh ya I know that i dont want to restrict myself to just one language. php is just a starting language as i plan to learn and use many other languages its just that too much is going on and there is a limit to how much time i can spend learning new things. things that confuse me a lot is comunicating between servers as I still lack the knowledge to understand how exactly they works. but its all cool you can always learn until you are alive. BTW I am also going for business major.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.