Page 1 of 1

Simple MySQL DB query

Posted: Wed Oct 14, 2009 4:13 pm
by bound4h
My website is hosted via a hosting company, and I believe they use Linux (because the file structure is like /usr/home/USERNAME/www) and there are etc bin, etc at the "usr" level. Not sure if that helps though. I can access cpanel for my site, and I have created a simple MySQL db with one table. I have 2 users. One can do all privileges and one can only select.

Now, the entire site was made in php (by the hosting company as a service that I paid for). My question is, I want to create a simple php script to query the database (named "stores") and the table named "store_info". I can use either username right? Or should I just use the limited user or does it matter?

Anyway, I understand basic SQL syntax SELECT * FROM store_info WHERE unit_num="value". The value will come from a search box above. So picture just a simple text box, where a user would input a 5 digit number and then hit a submit button. Then, right below it, a table would show the results (the store number is the primary key in the table). What is the simplest way to do this? How do I "connect" to the database via php since I don't actually have access to the physical server? Do I need access to the server? Do I just use the server's IP as a host?

Thanks guys,

Re: Simple MySQL DB query

Posted: Wed Oct 14, 2009 4:36 pm
by Christopher
The only access you need is to be able to upload PHP files to the server -- assuming that your host has setup MySQL for you. Check the PHP manual for PDO it will show you how to connect and fetch records.

Re: Simple MySQL DB query

Posted: Wed Oct 14, 2009 4:41 pm
by bound4h
What files would I need to upload? You mean to load the tables with data?

Re: Simple MySQL DB query

Posted: Wed Oct 14, 2009 5:28 pm
by Christopher
No ... a PHP script to search the stores table and display the results. The code in that script will connect to the database and fetch records.

Re: Simple MySQL DB query

Posted: Thu Oct 15, 2009 3:00 pm
by bound4h
Can you give a simple example as to the php connect string? I checked out the PDO documentation but that is very in depth for just one string.

Code: Select all

mysql:host=localhost;port=3307;dbname=testdb
Would that be correct if the host port and dbname were my own?

Re: Simple MySQL DB query

Posted: Fri Oct 16, 2009 4:12 am
by litarena
You should find yourself a php database connection tutorial. Your connection string is pretty good, of course you need a username and password too. But you hinted at that in your first posting. But you really need to follow a simple php/mysql tutorial.

Like this one here:
http://www.freewebmasterhelp.com/tutorials/phpmysql