PM me your email address, and I`ll send you a custom database class that I wrote that makes it incredibly simple to work with MySQL in PHP. I use it in every project I do, and it's saved so much time, also makes clean easy to read code.
All you need to do is to include the file on your page:
PHP Code:
require_once("/server/path/to/site/classes/database.php");
and then use the following code.
To read in data:
PHP Code:
$sql = "SELECT id, username FROM table";
$db = new Database();
$db->dbOpenDatabase();
$results = $db->dbResults($sql);
$db->dbCloseDatbase();
This returns an array in results containing all the records, to display the data you use:
PHP Code:
foreach($results as $record){
echo $id . " - " . $username . "<br>";
}
To add a record:
PHP Code:
$sql = "INSERT INTO tablename (username) VALUES('tbp')";
$db->dbOpenDatabase();
$db->dbAddRecord($sql);
$db->dbCloseDatabase();
To update a record:
PHP Code:
$sql = "UPDATE tablename SET username = 'tbp-new' WHERE username='tbp'";
$db->dbOpenDatabase();
$db->dbUpdateRecord($sql);
$db->dbCloseDatabase();
And to delete a record:
PHP Code:
$sql = "DELETE FROM tablename WHERE username = 'tbp'";
$db->dbOpenDatabase();
$db->dbDeleteRecord($sql);
$db->dbCloseDatabase();
All the MySQL connection and associated code to read records etc is handled internally by the class so you don't have to worry about it.
As you can see it makes it incredibly easy, you just need to know the relevant SQL and the class does the rest.
The same goes to anyone else, anyone wants a copy I`m quite happy to give it out, just PM me with your name and email address and i`ll send it over.