Something like this:
<?
class SortableExample {
var $conn;
var $user = 'test';
var $pass = 'test';
var $dbname = 'scriptaculous';
var $host = 'localhost';
function __construct() {
$this->conn = mysql_connect($this->host, $this->user, $this->pass);
mysql_select_db($this->dbname,$this->conn);
}
function getList() {
$sql = "SELECT * FROM categories ORDER BY orderid";
$recordSet = mysql_query($sql,$this->conn);
$results = array();
while($row = mysql_fetch_assoc($recordSet)) {
$results[] = $row;
}
return $results;
}
function updateList($orderArray) {
$orderid = 1;
foreach($orderArray as $catid) {
$catid = (int) $catid;
$sql = "UPDATE categories SET orderid={$orderid} WHERE catid={$catid}";
$recordSet = mysql_query($sql,$this->conn);
$orderid++;
}
}
}
?>
Note that you must manually call __construct as this is not automatically done in PHP4.
So in PHP5 you would do:
$mySortable = new SortableExample();
in PHP4:
$mySortable = new SortableExample();
$mySortable->__construct();
Optionally you can change the __construct name to your classname to achieve the same "effect" as in PHP5.
function __construct becomes function SortableExample