Easy usage of databases in PHP
When I started with development for PHP I did offend run into writing specific MySQL database code over and over in all my files. After suddenly running into something called Postegres SQL I quickly learned that this was not a good approach. I did also learn that it was really hard to debug database error with default error information, especially after the site was deployed for public usage.
So I decided to write the kill class that would solve all this small problems. The result was a simple database wrapper class container the most important functionality as:
- Connect
- Query
- Get next record in result (Perfect suited to be used with while loops)
- Get number of affected rows for SELECT, UPDATE, DELETE, INSERT
- Optimize table
- Clear result to free up memory
- Close connection
Get next record snippet
function next_record() { $this->Record = mysql_fetch_array($this->Query_ID); $this->Errno = mysql_errno(); $this->Error = mysql_error(); $stat = is_array($this->Record); if (!$stat) { mysql_free_result($this->Query_ID); $this->Query_ID = 0; } else { $this->Row += 1; } return $this->Record; }