This is my goal.
I have 16 receipts from gas stations that I have collected over the last several months. I wrote the mileage on them as well. So I thought it would be a great project to learn how to create a database class by logging these receipts. So I created a database on localhost called Gas and a table called stats. I figured this table would consist of these items
ID - Primary key
miles - the miles at time of fill up
amount - how much the gas cost
gallons - how many gallons
date - the date of purchase
I figured this database could teach me many things.
1. I would need to use code to organize all the receipts. I don't want to sit here and try to figure out each date of purchase. I want to just put them in and let the code organize by date
2. I would be able to do math on the gallons to figure out my mileage
3. I could do math on the amount to figure out my total cost of driving my car
4. I could do math on the date to see how many days of driving I get between fill ups
I am considering buying a new truck. I think knowing how much It cost me to drive my car around would really help when deciding if going from a car that should be getting about 26 miles to the gallon is worth trading to a truck that gets about 19. My car is a 2001 so I figure I have lost some mileage and the gap wouldn't be that bad. Of course I could just use a simple spreadsheet but then I wouldn't learn anything about databases and classes. This is an actual real world example that can be used by anyone
Creating the database in phpmyadmin isn't that hard but creating a class that connects in an OOP way is proving a little more difficult. I understand some of the principals but I ran into trouble trying to figure out the difference between
mysqli_connect
mysqli_query
$conn = new MySqli
For example, I put the name of the database in the some of them but for some reason my code told me that no database was selected. This didn't make sense.
For me, I see many different ways to make a class. There are the easy ways and there are the more difficult ways. The more difficult ways include advanced php programming skills. If that makes sense.
Like you could easily use a procedural method of connecting and working with the database and then take it one step up by creating a class and then you could go one step further by making your class use more advanced techniques. So my final goal would be
Code: Select all
class Database
{
public function connect() { }
public function disconnect() { }
public function select() { }
public function insert() { }
public function delete() { }
public function update() { }
}
Then I want to make a front end way of entering the information. So that is what I am up to.