DBPersister

Finally here you are, I’ve been expecting you!

DBPersister (database persistent library)  is a new and revolutionary library written for php language that helps you to use simply and clearly your database taking advantage of the powerful object oriented programming.
Who knows the complexity of the SQL language for querying data will appreciate the potential of DBPersister since the examples below.

What we will create in the following example is a message system in which a message is first stored in the database and subsequently recovered.
Once you have read the  example below, you will realize you have not written a single line of sql code!

1 – Create the table on your database:

  1. CREATE TABLE `POSTS` (
  2. `idMessage` int(11) NOT NULL AUTO_INCREMENT,
  3. `subject` varchar(100) NOT NULL,
  4. `message` longtext NOT NULL,
  5. `dateCreated` datetime DEFAULT NULL,
  6. `dateEdited` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  7. PRIMARY KEY (`idMessage`)
  8. ) ENGINE=MyISAM DEFAULT CHARSET=utf8

 

2 – Configure your database settings into the file DbMySqli_Settings

  1. /**
  2. * database host location
  3. * @var string
  4. */
  5. public $host = "localhost";
  6.  
  7. /**
  8. * database username used to connect
  9. * @var string
  10. */
  11. public $user = "root";
  12.  
  13. /**
  14. * database password used to connect
  15. * @var string
  16. */
  17. public $password = "";
  18.  
  19. /**
  20. * database name used to operate
  21. * @var string
  22. */
  23. public $database = "test";

3  – Create a php class that maps the table created . In this example, we will use the name  Post.php

  1. <?php
  2.  
  3. class Post extends DbMySql_Persister
  4. {
  5.     public $idMessage;
  6.     public $subject;
  7.     public $message;
  8.     public $dateCreated;
  9.     public $dateEdited;
  10.  
  11.     /*
  12.   * Set the primary key of the table
  13.   */
  14. public function getPrimaryKey()
  15.     {
  16.         return "idMessage";
  17.     }
  18.  
  19. /*
  20.   * Set the table name
  21.   */
  22.     public function getTableName()
  23.     {
  24.         return "POSTS";
  25.     }
  26.  
  27.     public function __toString()
  28.     {
  29.         return (string) $this->subject;
  30.     }
  31.  
  32. }
  33.  
  34. ?>

 

4 -  Create the file test.php

  1. <?php
  2. require_once("DbMySql_Persister.php");
  3. require_once("Post.php");
  4.  
  5. $post = new Post();
  6. $post->findByPrimaryKey(10);
  7.  
  8. echo $post->message;
  9.  
  10. $post->message .= " add text....";
  11. $post->update();
  12.  
  13. $post->findByPrimaryKey(10);
  14. echo "<br>".$post->message;
  15. ?>

 

Google it! / Yahoo it! / Bing it! / Ask it!

DBPersister Comments

DBPersister comments

Powered by Facebook Comments

Leave a Reply

EnglishFrenchGermanItalianPortugueseRussianSpanish

Statistics

Visits today: 8
On Line: 0

Donate

Thank for your support

Follow

Get every new post on this blog delivered to your Inbox.

Join other followers: