PHP Classes

More additions

Recommend this page to a friend!

      dm.DB  >  All threads  >  More additions  >  (Un) Subscribe thread alerts  
Subject:More additions
Summary:More additions whicvh i think could be helpful
Messages:5
Author:stephen
Date:2005-05-07 18:02:47
Update:2005-10-13 18:27:55
 

  1. More additions   Reply   Report abuse  
Picture of stephen stephen - 2005-05-07 18:02:47
/**
* Lock A Table Item.
*
* @param Table Name, A Lock Type
* @access public
*/
function lock($table, $mode="write") {
$this->connect();

$query="lock tables ";
if (is_array($table)) {
while (list($key,$value)=each($table)) {
if ($key=="read" && $key!=0) {
$query.="$value read, ";
} else {
$query.="$value $mode, ";
}
}
$query=substr($query,0,-2);
} else {
$query.="$table $mode";
}
$res = @mysql_query($query, $this->dblink);
if (!$res) {
$this->return_error("lock($table, $mode) failed.");
return 0;
}
return $res;
}

/**
* unlock A Table Item.
*
* @param Table Name
* @access public
*/
function unlock() {
$this->connect();

$res = @mysql_query("unlock tables");
if (!$res) {
$this->return_error("unlock() failed.");
return 0;
}
return $res;
}



/**
* Grabs A single field .
*
* @param FieldName
* @return Values of the Filed
* @access public
*/
function field($Name)
{
return $this->record[$Name];
}


  2. Re: More additions   Reply   Report abuse  
Picture of Richard Munroe Richard Munroe - 2005-05-09 20:07:27 - In reply to message 1 from stephen
Looks reasonable on the surface of it. I'll take a quick glance at the lock documentation on the MySQL site to make sure what you've done makes sense. If so, I'll just include it.

What do you want a field fetch. I would have thought that once you've fetched the record, you would just grab the data from the returned array. Or are you trying to avoid copying the data? In which case what should probably be happening is returning a reference to the records rather than the records.

Dick

  3. Re: More additions   Reply   Report abuse  
Picture of stephen stephen - 2005-05-09 23:17:58 - In reply to message 2 from Richard Munroe
Its just me being very very lazy

  4. Re: More additions   Reply   Report abuse  
Picture of Richard Munroe Richard Munroe - 2005-05-10 15:08:53 - In reply to message 3 from stephen
You might want to take a look at the SQLData class which, amoung other things, has a script called buildClass.php which builds a full object oriented interface to your tables, then you can use things like:

$t->getField()

to access things. The SQLData and the dm.DB classes interact to give you powerful and simple access to your tables. A little more mechanism, but you get something for it, for example, after you've made all changes to your data using the class you created you can simply:

$t->update()

and the class figures out what's changed, what the key fields to use are, and does the update for you.

I've even published a paper on how this stuff got created. It's NOT a programming manual but it justifies the use pretty well. Check out:

http://www.csworks.com/publications/APG.pdf

Dick

  5. Re: More additions   Reply   Report abuse  
Picture of Richard Munroe Richard Munroe - 2005-10-13 18:27:55 - In reply to message 4 from Richard Munroe
I finally got around to updating with the lock/unlock functions you provided. As per our earlier discussion I WON'T add the fetch function as I think that is better provided by a table level abstraction provided by SQLData. Thanks again for the suggestion and the code and my apologies for taking so long to add the functionality.

Dick Munroe