Simple MySQL DB query

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bound4h
Forum Newbie
Posts: 5
Joined: Wed Oct 14, 2009 4:07 pm

Simple MySQL DB query

Post 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,
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Simple MySQL DB query

Post 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.
(#10850)
bound4h
Forum Newbie
Posts: 5
Joined: Wed Oct 14, 2009 4:07 pm

Re: Simple MySQL DB query

Post by bound4h »

What files would I need to upload? You mean to load the tables with data?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Simple MySQL DB query

Post 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.
(#10850)
bound4h
Forum Newbie
Posts: 5
Joined: Wed Oct 14, 2009 4:07 pm

Re: Simple MySQL DB query

Post 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?
litarena
Forum Newbie
Posts: 14
Joined: Tue Sep 01, 2009 3:39 am

Re: Simple MySQL DB query

Post 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
Post Reply