Help with MySQL!!
- Semiperfect
-
Semiperfect
- Member since: Sep. 15, 2002
- Offline.
-
- Forum Stats
- Member
- Level 02
- Blank Slate
Okay, MySQL has me thoroughly frustrated.
I know how to call the database with PHP. The problem is, how do I connect to MySQL on my server?
I know where MySQL is on the server, but I cannot connect to it, and my provider has no idea what I am talking about (the provider is actually one of my staff's dad). Should I just FTP my own database and connect to that, or what??
This is giving me a real headache...
- liljim
-
liljim
- Member since: Dec. 16, 1999
- Offline.
-
- Send Private Message
- Browse All Posts (11,644)
- Block
-
- Forum Stats
- Staff
- Level 28
- Blank Slate
At 9/15/02 10:54 PM, Semiperfect wrote: Okay, MySQL has me thoroughly frustrated.
I know how to call the database with PHP. The problem is, how do I connect to MySQL on my server?
I know where MySQL is on the server, but I cannot connect to it, and my provider has no idea what I am talking about (the provider is actually one of my staff's dad). Should I just FTP my own database and connect to that, or what??
This is giving me a real headache...
Check out the PHP Manual Entry on connecting to your database. You have your username and password, right?
The MySQL server that you're connecting to - it's on the same server as your site? If so, it should be as simple as doing:
$connection = @mysql_connect("localhost", "your_username", "your_password")
or die("Unable to connect to MySQL server. MySQL said: " . mysql_error());
$db = @mysql_select_db("your_database_name", $connection)
or die("Unable to select the database which is to be used for the queries. MySQL said: " . mysql_error());
Where:
localhost is the default name for the local machine - if you're connecting to mysql on a different server, then you need to put the name of the server here.
your_username is the name your host has provided you with for you to connect to the mysql server.
your_password is the password your host has provided you with to connect to the mysql server.
When querying mysql, you must select a database. That's what the second function does. your_database_name should be replaced with the name of the database your host has provided you with.
If you're still having problems at this stage, then mysql may be set up on another port. Read more on the link I've provided you with to investigate that.
Of course, the example that I've provided you with is just that - a simple example. In production mode, you shouldn't return errors you might get from your database with the mysql_error() function, since it provides anyone who's connecting (potentially bad people!!) to know what's wrong with your connection / queries, should something go wrong. This provides them with more information on your database / setup of tables than you want. You can, instead, create your own functions to "fail gracefully", and even to write the contents of any error messages on connecting / querying the database to a flat file, so that you can see what went wrong in your own little administration suite (if you care to set one up).
- asp55
-
asp55
- Member since: Sep. 14, 2000
- Offline.
-
- Forum Stats
- Member
- Level 06
- Blank Slate
Um what do you mean "connect to the MySQL on yer server"
if you mean the connect command its in the php.net function list and to be exact it is
mysql_connect("mysql_host", "mysql_user", "mysql_password")
or die("Could not connect");
But since I'm assuming that you mean like connect to the database and edit it directly, that'd be done through telnet/ssh all that is in the documentation on mysql.com.
Hope thats helpful. If not, give me an IM or drop me an email, if I'm available I'd be glad to help ya.
-asp55
http://col.neoki.net

