by DAn BLaisdell
Introduction
DABL is designed to make the repetitive tasks of database access easier using the Object-Oriented functionality of PHP 5. DABL builds PHP classes to represent each table in your database. Using these classes, table rows can be created, retrieved, updated, and deleted using very simple and short commands. These classes are generated based on the information schema of your database, so there is no need to look at the table structure at runtime, and foreign key relationships can automatically be turned into useful class methods, whether they are one-to-many or many-to-one ($customer->getOrders() or $order->getCustomer()). These classes can also be used to avoid writing raw SQL.
This software is inspired by and is used almost exactly like Propel, but is much easier to install (no command line needed, which means it can run easily on a shared hosting server), uses less code and fewer files, and doesn’t use Peer classes for static functions. It also has a class for building queries, Query, which is similar to Propel’s Criteria, but is more flexible and can be used independently. The goal of DABL is to make the brilliance of Propel and other ORMs more accessible to developers.
DABL will create two class files for each table in your database. The first one, located in classes/tables/base contains all the native DABL methods. This “base” class is abstract and cannot be used on it’s own. The base class should not be modified manually, because it will be replaced the next time you run mapDB.php. The second one, located in classes/tables has the same name as the table, and is the class that should be used. This second class extends(inherits the properties and methods of) the first and is initially empty. It can be edited to contain custom properties and methods for your specific application, and once it has been created, it will not be modified when you run mapDB.php.
DABL uses PDO, which should be available on most servers with PHP 5 installed. In the event that your hosting does not have PDO installed, DABL comes with an emulator. If your hosting has PDO installed, but does not have the PDO drivers for your database, you will have to rename the PDO classes to something like _PDO, and adjust all of your code accordingly, so that the emulator does not conflict with the real version.
DABL was written for MySQL, but versions 1.1+ include modified(simplified) versions of the database adapters included with Propel 1.3. We have not tested DABL on any of the other database types. We would greatly appreciate the input of developers who have experience with other database types.
Included adapters:
- MSSQL
- MySQL
- Oracle
- Postgres
- SQLite
Visit the Wiki / Project Manager
Documentation/Tutorials
- Download and Installation
- Inserting Rows
- Getting and Setting Column Values
- Selecting Rows
- Retrieving Related Rows through Foreign Keys
- Deleting Rows
- Counting Rows
- Populate Object Values from an Array
- Populate Array from Object Values
- Paginating Query Results
- Object Oriented Query Building
- Transactions
57 Comments »
RSS feed for comments on this post. TrackBack URL


Hello,
I really appreciate your work. The simplicity and the power of your orm is impressive so far. I also like the fact that you did not deal with complicated configuration stuff (xml, yaml…).
Your generator looks great (i tried it but i did not yet use the generated classes yet).
I plan to use your orm in a very simple php framework that i’m building, and I’ll follow your work very closely.
Simplicity end efficency is what all programmers should achieve.
Regards.
Comment by Bruno — April 20, 2009 @ 2:00 pm
Bruno,
Thank you for the feedback. I would love to see the framework that you put together when you are done. My documentation isn’t yet complete. I’ll add to it as soon as I can.
I just put up a slightly newer version today. I made a few changes to the QueryPager methods and I added ` symbols around column names when generating the CRUD queries, to avoid conflicts with mysql terms. Please let me know if you have any improvements or suggestions.
Comment by admin — April 21, 2009 @ 12:59 pm
Hi Dan,
I played a bit with DABL, and was very happy to be able to do the same things I was doing with Propel! It is just fantastic because like you I was looking for something lighter, simple and intuitive.
I’m gona use DABL in a project I’ve just started (it is an e-commerce website), so I can experiment all the features and help you improving … .
By now, I have some questions and remarques:
–> Can you explain a bit how you use the QueryPager class ?
–> The generated classes have as the same case as the database tables, wouldn’t it be intresting to force the generated classes to have the first letter in capital, ex. tables called user, hWnd, postsTags, will be represented by classes called User, Hwnd, Poststags… ?
–> Also it can by interesting to have getters and setters can be camelCased ($user->getName() instead of $user->getname() ) or underscored ($user->get_name()) … ?
–> At last I chaged the default “tables” folder location and rename it to models because I wanted “models” folder name and I wanted to put it in a diferent place say a folder named “mvc”, so I had to change paths in the DABL class…
I thong it will be great to configure the path and name of the class generation folder…
I’m gona give you more feedbacks while using DABL in a real and consistent application asap.
Bravo! for your work
Thanx
Comment by Bruno — April 24, 2009 @ 8:31 am
Thank you very much for the feedback. In response to your request, I created some documentation for the QueryPager. Regarding some of your other requests. I think it would make sense to force the first character to be uppercase for class names and the field names in the getters and setters. I probably wouldn’t force the rest of the characters to be lower case, so that if the database tables are camelCased, then it won’t ruin the word separation. I also think the option to change the class directory makes a lot of sense. It would probably have to be done in the config file, so that the Module system knows where to look. What do you think?
Comment by admin — April 24, 2009 @ 11:42 am
Hi Dan,
I think that’s fine for the class names, getters and setters.
The idea to setup the path to the generated classes in config file is excellent.
I’ll probably start to give you more feeback by the end of next week, when I’ll be working data models generated by DABL.
Rgds.
Comment by Bruno — April 25, 2009 @ 11:59 am
Hi Dan.
First of all, thanks for a job well done. Im using DABL and as far as I have used it, it fits all my needs. However, There’s something I havent quite figured out yet…
Im trying to create a query object where the condition is of the form (a&&(b||c)) where a,b and c are equality conditions (i.e. idUser=’1′). I looked at the source and saw an addOr methon on the query class, but I dont know how to use it for this purpose…
On the other hand…What is the license of DABL??
Comment by Pablo Marchant — May 4, 2009 @ 11:28 am
Hi Pablo,
You can create isolated conditions within () by using the Condition class along with the Query class. I just posted a tutorial on it here.
Comment by admin — May 4, 2009 @ 12:01 pm
thats an efficient suport!
thank you very much
Comment by Pablo Marchant — May 4, 2009 @ 12:09 pm
Your generator sounds interesting. I especially like the concept of automatically detecting table relationships and generating friendly named methods to load the dependencies.
I wanted to give this a try in my current project, but unfortunately I’m using PostgreSQL which is not supported. Having a quick look at your classes it seems that adding support for PSQL will require significant re-writing of queries, etc.
If you want this library to scale and grow, I suggest you start refactoring and abstracting your classes so that people can create new DB drivers for you. Abstracting the generated code into separate template files would also help clean up the DABL.php source, and could potentially allow for pluggable templates that could be written for other languages or customized as needed for specific projects.
Unfortunately DABL is not mature enough for my needs atm, but looks promising so keep at it!
Comment by Richard Gluga — May 4, 2009 @ 10:58 pm
Hy Dan,
first, let me say that I think DABL is great! I used it for a tiny little webservice I needed to write and didn’t want to spend a month on, and it worked like a charm. The only thing I had to fix was that very often, you use <? instead of <?php to denote code blocks. On my dev machine (a mac) this doesn’t work, so I had to change the respective lines. Otherwise, very cool! I hope you keep working on it, this seems to fill a gap in the market which the big systems like Doctrine etc can’t cover.
Ben
Comment by Benjamin — May 5, 2009 @ 4:22 am
Richard,
I appreciate your feedback and I completely agree with you. That’s why version 1.1 uses a modified version of Propel’s database adapter classes. I am no longer directly quoting identifiers, such as table names with ` or applying limits. Instead I’m using methods in the adapter classes. At this point, we have only confirmed that DABL will generate working classes for MSSQL and MySQL. Anything other than mysql will probably be buggy/not work, but I did my best to restructure as needed so that the support can be added to the individual database adapter classes. If you can get it working with Postgres, please send me your code!
Comment by admin — May 8, 2009 @ 4:23 am
Bruno,
As of version 1.1, DABL should now have upper-case classes and column names as you requested. It will do this now by default, but this feature can be turned off. You can also change the directories for the generated classes by passing some options the the generate method in tools/mapDB, but if you change them, make sure you point the autoload module to the new locations in the config file. Let me know how it works out for you.
Comment by admin — May 8, 2009 @ 4:31 am
Hi Dan,
Thank you very much. I’m gona download that version and test it.
Unfortunately, I didn’t seriously started tu manipulate DABL as I promised you, I’m so busy now with to many urgent projects to finish, so I apologize for that.
Nonetheless, the few things I tested where satisfactory.
Other features that would be interesting are:
- A validator
- A html fields generator
I know it’s a big big work but it’s worth to do that.
For me I added validation and fields generation to the models by using third party classes, that’s fine but may this is not the optimal solution…
If I can help you in some way, just tell me (my only problem would be to find the time…).
Comment by Bruno — May 9, 2009 @ 9:40 am
A little thing I would like to ask (been looking on the web but havent found much…)
I have some paid servers in wich php was compiled with the –disable-pdo flag. Is there any hope to make DABL work in that case?? Or I would have to start modifiyng the source to use directly mysql php functions (the databases on these servers are all mysql) instead of PDO??
Comment by Pablo Marchant — May 10, 2009 @ 1:01 am
What you need are classes to emulate pdo. Someone posted classes on phpclasses.hostgo.com that do just that:
http://phpclasses.hostgo.com/browse/package/2572.html
These classes do a lot, but they are built for php 4, so they are missing some key features. If I were to use these, I would take advantage of the php 5 technology and build some sort of PDOStatement emulator for the results and try to make these as close to the real thing as possible. Unfortunately we don’t have time to do all of this. If someone has a better PDO emulator package, please let us know!
Comment by admin — May 12, 2009 @ 10:33 pm
I must say thanks for make this so simple and efficient.
Better start a Wiki. It will grow fast.
Cheers
Comment by Leo Cabral — May 20, 2009 @ 10:29 am
I work with Mysql Innodb engine
How can I use transactions ? (begintransaction, commit and rollback)
Comment by lalevee — May 22, 2009 @ 1:44 am
Hi Dan,
I am on a relatively small prject with DABL and I’m satisfied.
Nonetheless 2 things didn’t go well:
- runnig php under E_ALL|E_STRICT gave me an error in BaseTable class about the static abstract methods, so I just turned them to regular static methods.
- the model generator tool still put generated subclass names in lower case, but the rest was camel cased as expected.
I added a functionality in the querypager class so that it can return a html paging content directly so that we dont have to play each time with many methods of the querypager to format navigation links.
the method is getPagingContent(…) and is easy to use, an example can be :
echo $actu_pager->getPagingContent(‘/actu/index.html?$pVar=$pValue’, ‘page’, ‘cCurent’, ‘cDefault’, array(‘prev’=>’previous page’, ‘next’=>’next page’));
$pVar and $pValue are part of the syntax and both are mandatory, $pVar will be replaced by the querystring paging var ie: page and $pValue will be replave by the value in order to format navigation links,
So acoording to the given pattern ‘/actu/index.html?$pVar=$pValue’, the navigation link will be ‘/actu/index.html?page=2 … so people are free to use any type of url rewriting like /anything/whatever_you_thing-of/$pVar/something-else/$pValue/ok-thatsall.xhtml…
Comment by Bruno — May 25, 2009 @ 3:37 am
And this is the code for everyone:
—————————————————-
/**
*
* @param string $urlFormat The url to format paging links with, ie: /news/list/$pVar/$pValue, $var and pValue are part of the syntaxe.
* @param string $queryStringVarName The var to look for in the query string to retrieve current page number, default is “page”
* @param string $cssClassCurrentLink The link tag css class where we are
* @param string $cssClassNotCurrentLink The link tag of the others
* @param array $linkExtra Ie: array(“first” => “go to first page”, “prev” => “previous”, “next” => “next”, “first” => “go to last page”)
* @return string Html paging content
*/
public function getPagingContent($urlFormat, $queryStringVarName=’page’, $cssClassCurrentLink=”, $cssClassNotCurrentLink=”, $linkExtra=array()){
$currentpage = $this->getPageNum();
$nbpages = $this->getPageCount();
$urlFormat = str_replace(‘$pVar’, $queryStringVarName, $urlFormat);
$str = ”;
if (isset($linkExtra['first']) && strval($linkExtra['first']) != ”)
if(!$this->isFirstPage())
$str .= ‘‘.$linkExtra['first'].’‘;
if (isset($linkExtra['prev']) && strval($linkExtra['prev']) != ”)
if(!$this->isFirstPage())
$str .= ‘getPrevPageNum(), $urlFormat).’”>’.$linkExtra['prev'].’‘;
for($i=1; $i<=$nbpages; $i++)
$str .= ‘‘.$i.’‘;
if (isset($linkExtra['next']) && strval($linkExtra['next']) != ”)
if(!$this->isLastPage())
$str .= ‘getNextPageNum(), $urlFormat).’”>’.$linkExtra['next'].’‘;
if (isset($linkExtra['last']) && strval($linkExtra['last']) != ”)
if(!$this->isLastPage())
$str .= ‘‘.$linkExtra['last'].’‘;
return $str;
}
}
Comment by Bruno — May 25, 2009 @ 3:38 am
Dan,
I also wanted to build a validation class and a html fields generator to generate input tags and validation that will performe php/javascript based validation and bundle them with a crud generator…
But I thought maybe your are already working on such tools ? (so it is not necessary for me to work on that)
Comment by Bruno — May 25, 2009 @ 3:46 am
I added a page that demonstrates how to use transactions:
http://manifestwebdesign.com/developer-resources/database-abstraction-layer/transactions/
Comment by admin — May 26, 2009 @ 1:05 am
Great Work Dan, License plans???
Comment by Oliver — May 26, 2009 @ 7:41 am
I will definitely be an open license, but I haven’t released anything publicly. I haven’t had time to look at the different options and copy and paste the text. I will probably go with the same license used by propel.
Comment by admin — May 29, 2009 @ 12:39 pm
Just released version 1.2. Juggles data types a little better, includes a pretty good PDO emulator for servers that don’t have the PDO extension, added delete and count methods for foreign keys, added a modified version of Bruno’s QueryPager link builder, and fixed a few warnings from strict mode (thanks to Bruno for pointing them out).
Comment by admin — May 31, 2009 @ 3:24 am
Thank you very much for the 1.2 update!
The included PDO emulator for mysql works like a charm. Guess ill only be missing transaction support, but I can live without that. Only issue ive found is with one of the servers I use, where PDO drivers are included, but php was compiled with –disable-pdo (wich makes the pdo drivers crash without doing a thing…), and when trying to use the replacement classes, I get errors because PDO classes are already defined. Well, guess Ill just have to change that server, since I cant configure anything there.
Anyways, Great Work! keep it coming
Comment by Pablo Marchant — May 31, 2009 @ 2:40 pm
Pablo,
I’m glad the emulator is working for you. I had the same thing happen to me with the PDO conflict once. One solution is to rename the PDO class to _PDO and change all the code accordingly.
Comment by admin — June 2, 2009 @ 10:51 am
Hi,
I am using your frame work only. Its really helpful to me.
Now i am able to achieve all things in two or three lines instead of bigger code.
Also. I am facing one problem. Can you help me out?
I can not use as $book->getAuthor(); It throws (“classs author not found”).
I have InnoDB and foreign key relationships between those tables.
Can you help me how to do?
Regards,
Ashok Raja CM
Comment by Ashok Raja CM — June 13, 2009 @ 2:52 am
If you are getting a “class not found” error and the class file has in fact been generated, then there is an issue with the autoloader not finding the file. I recently ran into a situation where this happened to be due to upper/lower case differences in the file name. I make a few fixes to the BaseTable.php and DABL.php classes in version 1.2.2. You may find that downloading that version and regenerating the classes fixes your problem. Beyond that, it would be hard for me to know exactly what’s happening without looking at your code. Hope that helps. Thanks joining the movement!
Comment by admin — June 17, 2009 @ 12:57 am
I had been checking your code since 1.0, and I have seen that the query class has methods that allow inclusion of join clauses. However, im not quite sure how to use them…
Do you have any example of the usage of join clauses??
Comment by Pablo Marchant — June 17, 2009 @ 11:48 pm
I just wanted to comment and thank you for writing this great ORM. It has saved me a lot of time, and it’s very easy to use. Keep up the good work and I look forward to future updates.
Thanks again!
Comment by Matt — June 18, 2009 @ 6:33 pm
Hi Pablo,
I added an example for joins to the “Object Oriented Query Building” page. Let me know if you have any questions about it.
Comment by admin — June 22, 2009 @ 2:28 pm
The db setup script didn’t work correctly for me. In the getters/setter for the baseX.php files it would generate lines like:
if($this->Object id #8 !== $theValue){
which gave syntax errors (obviously). So in DABL.php I changed:
if($this->’.$field.’ !== $theValue){
$this->_modifiedColumns[] = “‘.$field.’”;
$this->’.$field.’ = $theValue;
To
if($this->’.$field->getName() .’ !== $theValue){
$this->_modifiedColumns[] = “‘.$field.’”;
$this->’.$field->getName() .’ = $theValue;
and now it seems to work ok.
Comment by Andy — June 24, 2009 @ 9:55 pm
Hi! me again…
Just tested the joins. Zero problem, they work perfectly.
Also, Ive made an integration between Zend framework and DABL. So far, its working great. Only details though, I had to include the code from config.php directly into one of the files of Zend, and modified it a little so it can use the config file from my application, instead of hardcoding my database info.
Also, I added the mapDB tool as an action of a controller in the framework, so it integrates seamlessly into everything.
Aaaa, and a little detail I noticed in the versions posterior to 1.0 (I believe…), is that MEDIUMBLOB is no longer supported. When i first tested DABL, I used it to rewrite an old web app of mine that uses MEDIUMBLOB, and I had no problems with the generator. Now, it throws errors, saying that its not recognized. Is this because of the inclusion of the adapters? Is there a way to know what data types are supported?? In any case, I could very well settle with BLOB in case its supported…
Comment by Pablo Marchant — June 25, 2009 @ 11:11 pm
Pablo,
Yeah your issue is due to the Propel DB Adapters. Propel has it’s own system of data types and had some basic translation specifying what database data type equals what propel data type. If you look at DBAdapter::getColumns, you will see a switch that tries to add support for additional datatypes. This will probably need to be expanded/adapted for each database type. Right now it throws an exception if a type comes up that isn’t supported. Just add the missing type to that switch and you should be fine. I’m open to suggestions for the best way to work with this issue. I’m excited about your work with the Zend framework. Feel free to send code samples.
Comment by admin — June 26, 2009 @ 2:31 pm
Andy,
That is a strange error. What database type were you using and what were the names of the columns???
Comment by admin — June 26, 2009 @ 2:32 pm
If you’re interested in my work integrating DABL with zend, and want to check my source code, just give me an email where I can send you the source and a small explanation on how I “glued” these things up. Im still trying to figure out the best way to do things here (Zend framework is quite open on how you can work with it) so there’s still much work to do in it, though so far I like how things are coming out.
I plan to use this thing on a company to wich I belong at my university, where we mostly develop webapps with php.
Comment by Pablo Marchant — June 26, 2009 @ 9:39 pm
Hi dan,
Thank you for your work !
I use the function __auloading for all my classes in my application and I have a conflict with the name of your class DB and the DB package pear one. Will it be possible for you to change the name of your class ?
Thanks again.
Comment by Ray — June 30, 2009 @ 12:37 am
It’s me again
I have same problem of Andy. I used Mysql 5 / Inodb engine
abstract class baseOrigine extends BaseTable {
/**
* Name of the table
*/
protected static $_tableName = “origine”;
/**
* Array of all primary keys
*/
protected static $_primaryKeys = array(
“id”,
);
/**
* Primary Key
*/
protected static $_primaryKey = “id”;
/**
* Array of all column names
*/
protected static $_columnNames = array(
‘id’,
‘libelle’
);
protected $id;
protected $libelle;
/**
* Column Accessors and Mutators
*/
function getId(){
return $this->id;
}
function setId($theValue){
if($theValue===”")
$theValue = null;
if($this->id !== $theValue){
$this->_modifiedColumns[] = “Object id #47″;
$this->id = $theValue;
}
}
function getLibelle(){
return $this->libelle;
}
function setLibelle($theValue){
if($this->libelle !== $theValue){
$this->_modifiedColumns[] = “Object id #44″;
$this->libelle = $theValue;
}
}
other example
abstract class baseTR_LIB_ETAPE extends BaseTable {
/**
* Name of the table
*/
protected static $_tableName = “TR_LIB_ETAPE”;
/**
* Array of all primary keys
*/
protected static $_primaryKeys = array(
“LEP_ID”,
);
/**
* Primary Key
*/
protected static $_primaryKey = “LEP_ID”;
/**
* Array of all column names
*/
protected static $_columnNames = array(
‘LEP_ID’,
‘LEP_LIB’,
‘LEP_REQUIRED’,
‘LEP_CLASSE’
);
protected $LEP_ID;
protected $LEP_LIB = “”;
protected $LEP_REQUIRED = 0;
protected $LEP_CLASSE = “”;
/**
* Column Accessors and Mutators
*/
function getLEP_ID(){
return $this->LEP_ID;
}
function setLEP_ID($theValue){
if($theValue===”")
$theValue = null;
if($this->LEP_ID !== $theValue){
$this->_modifiedColumns[] = “Object id #16″;
$this->LEP_ID = $theValue;
}
}
function getLEP_LIB(){
return $this->LEP_LIB;
}
function setLEP_LIB($theValue){
if($this->LEP_LIB !== $theValue){
$this->_modifiedColumns[] = “Object id #18″;
$this->LEP_LIB = $theValue;
}
}
function getLEP_REQUIRED(){
return $this->LEP_REQUIRED;
}
function setLEP_REQUIRED($theValue){
if($theValue===”")
$theValue = null;
if($this->LEP_REQUIRED !== $theValue){
$this->_modifiedColumns[] = “Object id #7″;
$this->LEP_REQUIRED = $theValue;
}
}
function getLEP_CLASSE(){
return $this->LEP_CLASSE;
}
function setLEP_CLASSE($theValue){
if($this->LEP_CLASSE !== $theValue){
$this->_modifiedColumns[] = “Object id #10″;
$this->LEP_CLASSE = $theValue;
}
}
I use the solution, I replace in dabl.php
$class .= ‘
if($this->’.$field->getName().’ !== $theValue){
$this->_modifiedColumns[] = “‘.$field.’”;
$this->’.$field->getName().’ = $theValue;
}
}
‘;
by
$class .= ‘
if($this->’.$field->getName().’ !== $theValue){
$this->_modifiedColumns[] = “‘.$field->getName().’”;
$this->’.$field->getName().’ = $theValue;
}
}
‘;
Comment by Ray — June 30, 2009 @ 1:00 am
Ray and Randy,
I found out the issue for the generator. See this page:
http://devzone.zend.com/node/view/id/168
There is a section titled “__toString() or not to String” that explains what is happening to you. It is a bug with php’s __toString() magic function that I was not aware of. Your version of php 5 must have the issue while mine does not. I will change my code accordingly and put up a new version as soon as I can.
Comment by admin — July 3, 2009 @ 10:17 pm
Hey,
im using DABL now for 1 week and its really usefull, nice work. But i have a problem with joining tables.
The result of the query is correct, but the columns of the joining table will not responsed by DABL/PDO, dont know.
Well, if i execute my statement in phpMyAdmin everything looks ok.
My statement:
Q = new Query();
$Q->setTable(‘mod_news_content’);
$Q->addJoin(‘umgt_user a’, ‘a.UserID = mod_news_content.PublisherID’);
$Q->add(‘rk_applicationID’, $this->__AppID);
$Q->addColumn(‘a.DisplayName’);
$Q->addColumn(‘mod_news_content.*’);
$data = mod_news_content::doSelect($Q);
This will generate the following statement:
SELECT a.DisplayName, mod_news_content . *
FROM `mod_news_content`
JOIN `umgt_user` a ON ( a.UserID = mod_news_content.PublisherID )
WHERE rk_applicationID =3
LIMIT 0 , 30
PhpMyAdmin shows me all columns of mod_news_content and column ‘DisplayName’ of umgt_user. When i try var_dump($data); everything looks okay, but the column ‘DisplayName’ will not be displayed, its missing.
DABL joins the table,yes, but i didnt get the columns with their result of the joining-table
Can someone help me, what is my fault?
Thanks, joSh
Comment by joSh — July 7, 2009 @ 4:32 am
Hi, Dan
I thinks there a bug with number args of function setCharset. it’s declared with one and she is call with two args
thank.
public function initConnection(array $settings){
if (isset($settings['charset']['value'])) {
$this->setCharset($this, $settings['charset']['value']);
}
…….
}
public function setCharset($charset){
$this->exec(“SET NAMES ‘” . $charset . “‘”);
}
Comment by Ray — July 10, 2009 @ 4:18 am
DABL 1.2.3 is out today. It fixes Rays setCharset bug, Ray and Randy’s __toString bug, and I bundled some options into the generator for creating basic views and controllers, if you’re into that kind of thing.
Comment by admin — July 10, 2009 @ 4:25 pm
joSh,
From what I gather, you are wondering why the column from the table you joined, a.DisplayName, is not present in the mod_news_content objects return by mod_news_content::doSelect. This is because the mod_news_content class does not have a property for DisplayName, because it’s not part of that table. Currently, doSelect is limited in it’s ability to actually return the joined objects with each object – that’s a tricky thing to do, but you are only attempting to get an additional column. You have two options.
One is to get the DisplayName after you get all the mod_news_content objects, like this:
$data = mod_news_content::doSelect($Q);
foreach($data as $d){
//if you have innodb with foreign keys setup
$user = $d->getUmgt_user();
echo $user->getDisplayName();
}
This is one of the easiest ways to get joined data. This seems cleaner for me, because you are working with objects instead of columns.
The other way is to setup your mod_news_content class you hold the DisplayName, if it’s present in the query results. TO do this you must add a property to the class and override its fromArray method:
public $UserDisplayName;
public function fromArray($array){
if(@$array['DisplayName']) $this->UserDisplayName= $array['UserDisplayName'];
parent::fromArray($array);
}
hopefully that helps – and hopefully I am actually answering the question you are asking.
Comment by admin — July 10, 2009 @ 4:40 pm
Ray,
Sorry to hear about the DB conflict. We’ll have to think of a new name or try to get rid of that class altogether.
Comment by admin — July 10, 2009 @ 4:53 pm
DABL 1.3 has many important changes. DB has been renamed to DBManager. DABL has been renamed DABLGenerator. I cleaned up the MODULE class and changed its case to Module. I changed the autoload function to use spl_autoload_register() instead of __autoload() because it works better with other libraries. There is no longer a functions folder, because it contained the Module class, which should be in the classes folder, and other things that either weren’t needed or could be part of the config file. The DBAdapter classes no longer contain methods for retrieving database meta information. Instead I’m leaving them as the runtime adapters that Propel intended them to be, and I’m bundling modified(simplified) versions of the Creole meta drivers, which Propel uses to reverse engineer databases. The database schema of your database is read by the Creole drivers and converted into an xml format, which DABLGenerator can easily use for creating the classes. In the future I may bypass the XML, but it was easier to leave that step in for now, and it allows mapDB.php to save an xml copy of the schema, which may be useful. I’m expecting version 1.3 to work with MySQL, MSSQL, Postgres, and SQLite without any tweaks, but I don’t use anything but MySQL, so let me know. I don’t think Oracle will work without a little tweaking.
Comment by admin — July 12, 2009 @ 1:04 am
Hi Dan,
Thank you for new version.
I thinks that function insert() must return $count because the function save return $this->insert()
public function save(){
if($this->getPrimaryKeys()){
if($this->isNew())
return $this->insert();
return $this->update();
}
return $this->replace();
}
……
protected function insert(){
$conn = $this->getConnection();
$quotedTable = $conn->quoteIdentifier($this->getTableName());
$fields = array();
……
$this->resetModified();
$this->setNew(false);
// here, add a return value
return $count;
}
catch(PDOException $e){
throw new PDOException($e->getMessage().$queryString);
}
}
Comment by Ray — July 13, 2009 @ 11:01 am
Ray,
You are right, insert was not returning $count. I’ll update that as soon as I can. Thank you.
Comment by admin — July 13, 2009 @ 6:53 pm
DABL 1.3.2 is available. Insert now returns a $count, thanks to Ray. I also made a few other changes, such as removing ?> from the end of some files and changing Base::fetchSingle() to use array_shift() instead of array_pop().
Comment by admin — July 15, 2009 @ 9:17 am
New to DABL. I keep getting the following error when trying to run mapDB.php. Any help would be appreciated:
Fatal error: Uncaught exception ‘Exception’ with message ‘Unable to read database.’ in …\dabl\mapDB.php:68 Stack trace: #0 {main} thrown in …\dabl\mapDB.php on line 68
tracing out what $conn is set to in config.php line 40 just gives me:
DBMySQL Object
(
)
thx
Comment by brian — August 14, 2009 @ 10:57 am
forgiveness does not speak English (google translator xD), Using WampServer Version 2.0 and this is the error that gives me just put config in the name of the database and the mysql user and pass
Parse error: parse error in D:\GestionPacientes\dabl\classes\dabl\DABLGenerator.php on line 956
Comment by RanuTo — September 15, 2009 @ 8:45 pm
Hi,
How can I have scenario like below.
User Table has usr_id as primary key.
and Book table has author, reviewer (both are foreign keys of User Table).
But DABL is mapping object to one of the foreign key. How can i make two mappings?
Currently I am using DABL 1.2. How can i solve this case?
Thanks in advance.
Regards,
Ashok Raja CM
Comment by Ashok Raja CM — September 22, 2009 @ 5:29 am
Can anyone tell me how to perform UPDATE query via dabl layer. Do i need to add new method in my database class or there is any inbuilt function for the same?
Comment by Mukund — October 4, 2009 @ 11:33 pm
I am trying to use mapDB.php, but I get an error on line 956 of DABLGenerator.php. It looks like some code is missing.
it starts
<?php
}
public static function —
Comment by Wes — October 26, 2009 @ 2:56 pm
Mukund,
There is not yet a way to do a bulk update using the table classes. Typically with ORMs you want to work with each row as an object, which means looping through your objects and changing them. If you are dealing with such high amounts of data that loops and multiple database calls isn’t practical, then you can use the MyTable::getConnection() method to get the php PDO object and build your own update query. I hope that helps. Let me know if you have any suggestions on ways to improve this.
Comment by admin — October 28, 2009 @ 9:08 am
Wes, can you send me your file so I am sure we’re looking at the same thing. My copy seems to run and validate.
Comment by admin — October 28, 2009 @ 9:08 am
Ashok,
Your situation does happen from time to time. At some point I will make DABL more clever and build multiple methods for the foreign keys that don’t conflict. In the meantime, you can write your own methods for each column, such as $book->getReviewer() and $book->getAuther() with your own custom code. What I will eventually add is something more generic such as $book->getUserByAuthorID() and $book->getUserByReviewerID(), if AuthorID and ReviewerID were the columns in the Book table. That is what Propel does.
Comment by admin — October 28, 2009 @ 9:12 am
Brian,
An exception is being throw when mapDB tries to build your schema. If you change the following:
catch(Exception $e){
throw new Exception(“Unable to read database.”);
}
…to
catch(Exception $e){
throw($e);
}
…you’ll have some more useful information. If you think there is still a problem, please email or post the actual exception.
Comment by admin — October 28, 2009 @ 9:14 am