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,
Simple MySQL DB query
Moderator: General Moderators
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Simple MySQL DB query
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)
Re: Simple MySQL DB query
What files would I need to upload? You mean to load the tables with data?
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Simple MySQL DB query
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)
Re: Simple MySQL DB query
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.
Would that be correct if the host port and dbname were my own?
Code: Select all
mysql:host=localhost;port=3307;dbname=testdbRe: Simple MySQL DB query
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
Like this one here:
http://www.freewebmasterhelp.com/tutorials/phpmysql