views:

74

answers:

5

Not sure I fully understand what phpmyadmin does.

I created a database in phpmyadmin, and would now like to start accessing the data in it from php. However I have no idea where the database is?

Should I export in the phpmyadmin software? I tried that but it came up with a .sql file which can be opened in notepad and contains the SQL statements used to create the datbase and the one table inside. Basically that doesn't look like a database to me.

A: 

The MySQL server runs on a known port on a given server (EG: localhost), with a given database (EG, it might be called: "myDatabase"). You should be able to configure phpMyAdmin to point to that server, host, and database.

Justin Ethier
A: 

phpMyAdmin is just an interface to work with an existing MySQL database server. However you have configured phpMyAdmin to access the MySQL database is the same information you need to access it through PHP. You will need the server name/ip, username and password.

There are many tutorials available online that can help you get started.

Shawn Steward
can I not just drop the database (which I have now found in the program files/my sql/....../...) into my websites folder?
Jonathan
That's not a database, that's just a SQL script you exported that will allow you to recreate the database. The database is already on your machine, wherever you setup MySQL at. You can use the export SQL script if you need to recreate the database on another computer, such as your web host.
Shawn Steward
+1  A: 

phpMyAdmin is an application, written in PHP, to provide a convenient interface to your MySQL database in the browser. It's not needed in anyway to connect to the database server from PHP. To do the latter, you'd typically find the right function names from the PHP documentation and get some examples. Start here, for example: http://www.php.net/manual/en/book.mysql.php (and investigate mysql vs. mysqli vs mysqlnd options).

Your MySQL server will usually run on localhost:3306, but you have probably entered those details while setting up the phpMyAdmin install, anyway.

djc
No I know phpmyadmin is not needed to connect to the database from php.
Jonathan
+1  A: 

PHPMyAdmin is only a graphical front-end to the mySQL database.

PHP has built-in functions to access a mySQL database, those are totally separate from phpMyAdmin.

For reference, here is the PDO documentation which is one of several methods to access PHP, and definitely one of the more recommendable ones.

It is recommendable over mySQL because it supports parametrized queries by default, the lack of which made many PHP applications based on the standard mysql_* family of functions vulnerable to SQL injections. That is not to say that it's not possible to program safe scripts with the mysql_ functions, but PDO makes it easier.

The docs are a bit tough to get started with the subject, though. I'd wait, I'm sure someone will link to some good english-language tutorials.

Pekka
A: 

You have to write your own php code to interact with mysql.

phpMyAdmin is a tool to interact with mysql independantly of your own website.

When you EXPORT using phpMyAdmin it is basically taking what is in the database and creating a text file of its contents that you can save for backup. If you want to restore the backup, go into phpmyadmin and paste that text file into SQL and it will put it back.

There are PHP commands to use to retrieve, and store data from your database. I recommend you look at the php website for mysql functions.

There are some good examples there.

SethCoder