Page 1 of 1

MySQL - PHP Explanation please

Posted: Wed Jul 30, 2003 8:50 am
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

...

Posted: Wed Jul 30, 2003 9:16 am
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.

Posted: Wed Jul 30, 2003 9:58 am
by twigletmac
Have you given the 'guest' account access to the iamdb database?

Mac

Posted: Wed Jul 30, 2003 10:12 am
by Whil
no...
how?
thank you :)

Posted: Wed Jul 30, 2003 12:45 pm
by twigletmac
Do you have phpMyAdmin?

Mac

puzzled

Posted: Wed Jul 30, 2003 1:51 pm
by Whil
nope ?