Documentation

PHP CLASSES DOCUMENTATION CAN BE FOUND HERE

http://www.dbpersister.com/phpdoc/

 

GETTING STARTED

Use the library DBPersister is really simple, here what you need:
1 – Download the installation file dbpersister_setup.zip , unzip it, and save the file dbpersister_setup.php  to any directory within your web server can access. For example, if you are working locally, and the site you are developing can be reached at the address “localhost”, you may save the setup file in the root directory of your local server and then type in any web browser the following address: “http://localhost/dbpersister_setup.php”.
2 – In this step you will find a form that asks some credentials. Enter the host address that runs your mysql server, type the username and password used to access your database and the name of database to use.
(Note: this username need all privileges to read the mysql own database if you choose to build from scratch all classes)
3Choose the directory for your project, the default is set to the directory where you saved the setup file.

Now you can click the red button that says “Setup DBPersister library” as the image below:

Screenshot for DBPersister installer

the automatic procedure will create/update inside your project everything you need to start being productive. The program will create the following files:

  • Castable.php
  • DbMySql_initializer.php
  • DbMySql_Persister.php
  • DbMySqli_Settings.php

which are the library files. Also will create, always in the same directory, all classes mapping all the tables in your database: these are the files that you really need to start working by.
Alternatively you can make sure that the procedure creates only the library files, leaving you the task of creating by hand classes that map your tables. In that case just put the check mark on “I do not want to automatically map my tables, only install the library”.
On the homepage you can see an example of how to map a table creating a mapping file.

In fact, with the automatic installation, you don’t need to create classes that map to your tables, and neither the class for settings up database parameters , which is automatically created

Let’s take this simple example. I am a daredevil and I followed the installation procedure. And now what else have i to do?
Well, imagine that the test database contains a single table, the table “users”. The table “users” has an “id” field (primary key, auto_increment), a field “username” and “password” field.
The DBPersister installation procedure has created four php files mentioned above inside the directory “my_test_directory” and users.php file in the same directory.
What we simply do in our program is to include the php files users.php in the standard way, and use the class users in the standard mode in which you use objects in php language.

Suppose we have a php script that takes values from an html form (the username and password for a new user) and must save them in the user table. Check out this simple piece of code

  1. <?php
  2. /*
  3. * Filename: dbpersister_test.php
  4. * The library users.php is required for this script because i want to write a record in users table
  5. * users.php was automatic generated by installation script
  6. */
  7. require_once("my_test_directory/users.php");
  8. if(!empty($_POST['cmdSubmit'])) {
  9. $user = new users(); //instantiate an object type users that is mapped with your user table
  10. $user->username = $_POST['username']; //set the username field of users object
  11. $user->password = $_POST['password']; //set the password field of users object
  12. $user->insert(); // write inside users table a new record
  13. }
  14. ?>
  15. <html>
  16. <head> <title> DBPersister is cool! </title> </head>
  17. <body>
  18. <form id="testForm" method="POST" action="">
  19. <input type="text" id="username" name="username" value="enter you username" />
  20. <input type="password" id="password" name="password" value="enter you password" />
  21. <input type="submit" id="cmdSubmit" name="cmdSubmit" value="Create new user"/>
  22. </form>
  23. </body>
  24. <html>

This script inserts a new record in the users table by using the wrapper users.php. This class maps the fields in the users table, and we can access these fields using the table as an object, the object users. It is left to DBPersister library the onus of writing the query needed to save a new record. The insert () method called on the users object accesses the database and saves the record in the table for us.

The proposed example is deliberately simple, if  you  require further informations or explanations on how to use the library you can post on our forum.

There are other methods that the library makes available, and will be described one by one below as soon as possible.

DBPersister staff

DBPersister Comments

DBPersister comments

Powered by Facebook Comments

Leave a Reply

EnglishFrenchGermanItalianPortugueseRussianSpanish

Statistics

Visits today: 11
On Line: 0

Donate

Thank for your support

Follow

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

Join other followers: