Archived

This topic is now archived and is closed to further replies.

doctorsixstring

MySQL w/ PHP

Recommended Posts

I am trying to connect to my MySQL database. Below is a snippet of my PHP file:
<?php

    /* Connecting, selecting database */
    $link = mysql_connect("localhost", "username", "password")
        or die("Could not connect : " . mysql_error());
    print "Connected successfully";
    mysql_select_db("db_name") or die("Could not select database");
I am having trouble figuring out what the hostname, username, and password is. I just installed MySQL and PHP, and I am a total DBA newbie. Where would I find/modify this info? Thanks, Mike

Share this post


Link to post
Share on other sites
The documentation on http://www.mysql.com is really great. Take a look at the online documentation with user comments. I always find the comments that people leave very helpful.

User information is kept in the mysql database in the user table.
Take a look at the docs for GRANT/REVOKE on how to add users. There''s also a SET PASSWORD command. The first thing you''ll want to do is to set the root password.

hmm..Do you even know if you have the mysql daemon running? On unix, you''ll want to start the mysqld daemon. On windows you want to run mysql as a service.

Good luck, read the docs lots.

Share this post


Link to post
Share on other sites
quote:
Original post by doctorsixstring
I am having trouble figuring out what the hostname, username, and password is. I just installed MySQL and PHP, and I am a total DBA newbie. Where would I find/modify this info?



By default ( at least under linux anyways ) the hostname is ''localhost'' the username is ''root'' and there is no password so you can use "". There are some good GUI''s on www.mysql.com''s site that let''s you do database admin things like add different users so you don''t have to use root all the time.




-------
Andrew
PlaneShift - A MMORPG in development.

Share this post


Link to post
Share on other sites
I started learning MySQL and Php about three weeks ago and absolutly nothing proved more valuable to me than "MySQL, The definitive guide..." by Paul DuBois. It covers MySQL in tons of detail, including setup of MySQL and Php, and a big section of MySQL and Php working together. Seriously, the online documentation for it is horrendous, except on phpfreak.com, so get the book!

Share this post


Link to post
Share on other sites
If you just install the MySQL server, the server doesn''t have any password and usernames. So, to connect to the database you have to use as username ''root'' and no password. This will work.

However, it is adviseable to add a user with a password. Get MySQLCC of the MySQL site and use it. It''s a great tool to setup accounts, create databases, etc.

Toolmaker



-Earth is 98% full. Please delete anybody you can.

Share this post


Link to post
Share on other sites