Connecting to mySQL problem in PHP

Problems with the Windows version of XAMPP, questions, comments, and anything related.

Connecting to mySQL problem in PHP

Postby Angel Dust » 28. December 2007 08:05

Hi I've downloaded XAMPP because I was looking at doing a bit of PHP and mySQL at home to complement my current university studies. The problem is while I can code a bit I don't know how to set anything up! I have managed to figure out how to get normal php stuff working but connecting to mySQL has become a bit of a problem.
I know that the php code involves this

mysql_connect(servername, username, password)

however I have no idea what those three variable are. I've tried opening up the WinMySQLAdmin control panel and looking around there but I'm unsure of what I'm seeing!

Thanks in advance for any help!
Angel Dust
 
Posts: 2
Joined: 28. December 2007 07:56

Postby Izzy » 28. December 2007 09:17

WinMySQLAdmin is now deprecated.

After starting Apache and MySQL go to:
http://localhost/
in your browser and check out all the menu items including phpMyAdmin which will give you a GUI for MySQL - it has much documentation and links to explore.

You can experiment by creating a database on the localhost server, giving that database a user with a password and permissions for that database - which might help with your understanding of that code snippet you posted:
mysql_connect(servername, username, password)

There are several posts about this subject and one that may interest you at this stage relates to creating a database for WordPress but may be used for any database creation.
http://community.apachefriends.org/f/viewtopi ... 258#112258
HTH


===========================================
1. The new DeskTopXampp Launch Control for XAMPP / XAMPPlite
Posted by Ridgewood available from Ridgewood'sDTX web site

2. Build Rich AJAX Applications - Faster
TIBCO General Interface Pro Edition but FREE and Open Source
Fully working with NO donations required to get a user/password
===========================================
Izzy
 
Posts: 3344
Joined: 25. April 2006 17:06

Postby KallistaAEnvarou » 28. December 2007 10:50

To make a new user, all you need to do is go to http://localhost/phpmyadmin and select the users table from the mysql database, click "insert" and insert the information. Then, add the user to the db database like you did to the users table. Lastly, you'll need to click "sql" and then type FLUSH PRIVILEGES. You can code an automatic adder if you want, but you'd have to connect to the database with your root user.

It's wise for you to research minimal permissions as a method of sql-injection prevention.
KallistaAEnvarou
 
Posts: 126
Joined: 02. December 2007 17:33
Location: Cold Cold California

Postby sari42 » 28. December 2007 12:22

KallistaAEnvarou wrote:To make a new user, all you need to do is go to http://localhost/phpmyadmin and select the users table from the mysql database, click "insert" and insert the information. Then, add the user to the db database like you did to the users table. Lastly, you'll need to click "sql" and then type FLUSH PRIVILEGES.
there is an easier way in phpMyAdmin:
login as superuser(root)->main->Privileges->Add a new user ...

Advantage: no flush privs needed, optional adding of
host, password, grants on special db ....

@Angel Dust:
there are tons of tutorials out there, amongst the first hits from google, e.g.,
http://www.freewebmasterhelp.com/tutorials/phpmysql
Last edited by sari42 on 28. December 2007 12:34, edited 1 time in total.
sari42
 
Posts: 800
Joined: 27. November 2005 18:28

Postby KallistaAEnvarou » 28. December 2007 12:26

That way's too confusing for me.

btw If you use my method, when you make the password, make sure to go to the left and choose PASSWORD as the function, or else you won't be able to connect. Sorry about leaving that out. The above method doesn't require this step.
KallistaAEnvarou
 
Posts: 126
Joined: 02. December 2007 17:33
Location: Cold Cold California

Postby Wiedmann » 28. December 2007 12:30

That way's too confusing for me.

Maybe, but your way is still deprecated!
If you (or someone other) want use another easy way: Just use the GRANT command in the SQL window (or use this command in the mysql shell client, without using phpMyAdmin).
Wiedmann
AF Moderator
 
Posts: 17102
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Postby KallistaAEnvarou » 28. December 2007 12:39

That's still too confusing for minimal permissions, at least on my part. I need to revert back to my code-based, automatic method, but I'm too lazy to remake my form. Now, OP, if you want, you can just run a php page like this:

mysql_connect(localhost,root,root_password);

mysql_select_db('mysql');

mysql_query("INSERT INTO users (host,user,password,[privileges desired]) VALUES('localhost', $username, PASSWORD('$password'), [2 for each privilege desired])");

mysql_query("INSERT INTO db (host, db, user, [privileges desired] VALUES('localhost', $dbname, $username, [2 for each privilege desired])");

mysql_query("FLUSH PRIVILEGES");

mysql_close();

So, for example, if you wanted just insert and select for me_is, you could do...

mysql_query("INSERT INTO users (host, user, password, select_priv, insert_priv) VALUES('localhost', $username, PASSWORD('$password'), 2, 2"));

mysql_query("INSERT INTO db (host, db, user, select_priv, insert_priv) VALUES('localhost', $dbname, $username, 2, 2"));

for the queries.

Then you could maybe put this in localhost and then do a form for it like I do, where you input the information and choose the privileges and passwords, like they do on a live server.
KallistaAEnvarou
 
Posts: 126
Joined: 02. December 2007 17:33
Location: Cold Cold California

Postby sari42 » 28. December 2007 12:41

Wiedmann wrote:Just use the GRANT command in the SQL window (or use this command in the mysql shell client, without using phpMyAdmin).
OK, using phpMyadmin is great for learning the mysql syntax,
as the used query is displayed on the resulting page.
Last edited by sari42 on 28. December 2007 12:42, edited 1 time in total.
sari42
 
Posts: 800
Joined: 27. November 2005 18:28

Postby KallistaAEnvarou » 28. December 2007 12:42

If you can get past the forms, yeah.
KallistaAEnvarou
 
Posts: 126
Joined: 02. December 2007 17:33
Location: Cold Cold California

Postby Angel Dust » 29. December 2007 13:05

Thanks for the prompt replies! I'll put all this into practice tomorrow and let you know how it goes.
Angel Dust
 
Posts: 2
Joined: 28. December 2007 07:56


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 77 guests