Archive for the ‘php’ Category

DBXMLAdmin updates

Thursday, May 29th, 2008

After being completely annoyed by SimpleXML earlier I decided it was time to look at DBXML again. This time I ran across a forum posting saying that DBXML 2.4.11 had a bug in it preventing updating. After upgrading to 2.4.13 I was able to update documents in a container. So I made some update to the project but realized that this was more of an out of control experiment than a real project. Already started redoing it, all the PHP is going to be new but I have managed to reuse most of the Javascript.

I also found this site DBXML With PHP, it is a small wiki for, as the name says, using DBXML with PHP. It has not been updated in a while (until today) but I will keep adding things as I progress on DBXML. Hopefully other will help out too, right now there are few resources for DBXML in PHP.

Phomet: A PHP Cometd publisher

Friday, January 11th, 2008

Created a small class last night that will allow you to connect, and then publish to a comet server. Code available here. Usage is simple.

$oPhomet = new Bayeux(‘http://whereis/my/cometd’);

$oPhomet->publish(‘/some/channel’, array(‘user’ => ‘derper’, ‘message’ => ‘wee’));

The deconstructor takes care of disconnected you from the server, but if you wish, you can use ->diconnect() before.

Using PHP to generate JavaScript classes

Saturday, April 28th, 2007

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.