Page 1 of 1

mysql host name

Posted: Mon Sep 22, 2008 9:32 am
by tawfiq
Hi there,

I would need some expert help, I really appreciate your time that you have taken to read my post.

Questions:

1. I am in a need to use username/password from a sql server, and MySQL for the rest of the site conent. So, basically I need to be able to connect to two databases (sometimes on the same page), one to retrieve username and maintain sessions, another to extract site content. Is that possible? I was thinking of having two include files - one for mssql one for mysql.

2. I have php on one machine, mysql on another and sql server on the 3rd machine. I can connect to the sql server but can't connect to mysql. I have tested it locally and mysql works fine with php. It's not recognising the host name while trying to connect remotely. I put the external IP/server name, none seemed to work. It only recognises localhost when tested locally. I have read somewhere mysql uses localhost as default host name. Does it mean I have to change mysql host name somewhere in my php.ini or in mysql configuration file? Or is there something I am missing. Please advise.

Many Thanks,

Re: mysql host name

Posted: Mon Sep 22, 2008 2:40 pm
by califdon
"Localhost" means precisely that: on the same machine that the web server is running on. You don't need to change anything in the .ini files, just in your connection string. The MySQL connection, in PHP, should look something like this:

Code: Select all

mysql_connect("k14mysql38.someserver.net","root","mypwd99") or die("Failed to connect to DB");
where the host name could be an IP address or URL, as shown above, or an internal LAN host name, depending on what kind of LAN you are using.

Oh, as to your first question, yes you can have more than one connection, either simultaneously or one after the other. I have never mixed database types in the same script, but I'm pretty sure that's not a problem. Just assign different resource handles to each one.

Re: mysql host name

Posted: Mon Sep 22, 2008 6:11 pm
by tawfiq
thank you very much, yes I have managed to get both databases working from the same script. I had to use two databases for a certain reason, but normally I use just one.