PHP to MySQL db connections?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
cleaner
Forum Newbie
Posts: 1
Joined: Mon Mar 17, 2003 7:58 pm
Location: Melbourne Beach

PHP to MySQL db connections?

Post by cleaner »

I understand the syntax and parameters of the basic "mysql_connect" command:

$db=mysql_connect("hostname","pw","un");

However, I've read and searched for hours now on mysql security and administration but can't find any specific information on how to connect to a remotely hosted db server using PHP on the web.

1) Do I have to create/grant a specific 'general' user account (un/pw) which can then be used in all my db connection scripts?

2) What is the best security strategy for web-based db connection and transactions?

Thanks in advance :!:
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

If you want to connect remotely then you need to set up a user on the MySQL database who has the right to connect from your IP address. You then replace 'hostname' in your mysql_connect() function call with the IP of the remote server. You will also (by default) have to have port 3306 open on the remote server so you will need to protect that.

http://www.mysql.com/doc/en/General_security.html
http://www.scibit.com/Help/mascon4linux/faq010.htm

Mac
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

Try using phpMyAdmin to do that, they make it very simple.

http://www.phpmyadmin.net/
http://www.mysql.com/doc/en/Privilege_system.html
Post Reply