MySQL - PHP Explanation please

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Whil
Forum Newbie
Posts: 8
Joined: Wed Jul 30, 2003 8:50 am
Location: USA

MySQL - PHP Explanation please

Post by Whil »

Hi,
I was hoping that someone could explain how php works with the mysql server :? I have gone through and read almost ALL of the PHP documentation and the MySQL documentation. I get most of the syntax but I dont grasp the concept behind it. When you connect to the mysql server via php you have the link command.
-> mysql_connect("localhost","user","password")
or die("Unable to connect to SQL server");
This just simply sets up the connection to the mysql server correct?
then comes where you connect to the database...
-> mysql_select_db("database") or die("Unable to select database");
does this connect you to one of the databases on the server? Or does it connect you to one of the tables? I dont get this. It looks to me like it is connecting to a database... But which one? Inside of the mysql server there are the databases "test" "mysql" and one that i created "iamdb".
I have also created another user besides the root user "guest" with a password.
when i try to connect to the "test" database everything works fine. When I try to connect to the "iamdb" database it does not work... Why? How do i fix that?
/me is confused /mysql noob
fyi My work forces me to use everything microsoft, but i am a inventory control programmer, i have lots of experiance with the microsoft sql server 2000, the jet engine and ado. (but i really would like to learn this mysql and php interaction (i hate vb!!))

-Thanks
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

...

Post by kettle_drum »

mysql_connect("localhost","user","password") - connects to the database at localhost and logs in as user:password. this is the same as typing mysql -u user -p password at the command propmt to start mysql.

mysql_select_db("mydatabase") - selects the database called "database" to use. This is the same as typing "use mydatabase;" in the mysql server. If you want to use iamdb, then use that instead of mydatabase.

Now that you have selected what database you are using you can issue an sql command to it to obtain the data - i.e. SELECT * FROM random_table;

I guess you know what all the "or die()" stuff means (if it fails stop running and print this error message).

Once youve managed to get connected to your database then just have a play about with all the possible mysql commands (check the php manual) and im sure youll pick it all up fast.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Have you given the 'guest' account access to the iamdb database?

Mac
Whil
Forum Newbie
Posts: 8
Joined: Wed Jul 30, 2003 8:50 am
Location: USA

Post by Whil »

no...
how?
thank you :)
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Do you have phpMyAdmin?

Mac
Whil
Forum Newbie
Posts: 8
Joined: Wed Jul 30, 2003 8:50 am
Location: USA

puzzled

Post by Whil »

nope ?
Post Reply