In the next couple of days I will be releasing the first version of my (A)JAJSON DB Interface (yeah). The main concept of my DBI is an Object represents a tables, and Classes are rows from the database.
$arr = array('users' => array('id' => 'int', 'name' => 'char', 'pass' => 'char'),
'comments' => array('id' => 'int', 'message' => 'char', 'when' => 'date'));
This is the array that would be assembled from the database by PHP.
Table users;+-------------+--------------+------+-----+---------+----------------+
|Field | Type | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(255) | NO | | | |
| pass | varchar(255) | NO | | | |
+-------------+--------------+------+-----+---------+----------------+
Table comments;
+-------------+--------------+------+-----+---------+----------------+| Field | Type | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| message | varchar(255) | NO | | | |
| when | timedate() | NO | | | |
+-------------+--------------+------+-----+---------+----------------+
Looping through this array, we can output JavaScript to prefab classes around tables in our database.
foreach($arr as $k => $v) {
echo "function {$k}() {}n";
foreach($v as $kk => $vv) {
echo "{$k}.prototype.{$kk} = {$vv};n";
}
}
This, put in a <script> tag, will give you a ready made object from your database. Further parsing would yield even better objects. Match types, like if type is int(anything) output Number() as $vv. Next is adding functions to do things with the content. An explanation of that will be coming up soon with the release of (A)JAJSON DBI.