Generate PHP Doctrine with MySQL

You can generate PHP code for accessing database with Visual Paradigm for UML. In this tutorial, we will generate PHP Doctrine, and create a sample PHP file for creating a record in database. Make sure you have PHP, MySQL and Apache webserver ready before you start this tutorial.

February 18, 2010
User Rating: / 4
Views: 6,026
PDF Link Add comments
Edition: Standard or above (Edition comparison)

  1. Download the project Farm Management.vpp attached with this tutorial.
  2. Start Visual Paradigm for UML.
  3. Open Farm Management.vpp
  4. Open Entity Relationship Diagram1 and take a look.
    database design
  5. Right click on the diagram background and select Synchronize to Class Diagram from popup menu.
    sync to class diagram
  6. Click OK in Synchronize from Entity Relationship Diagram to Class dialog box.
  7. Click OK in Synchronize to Class Diagram dialog box. This produce a class diagram.
    class diagram formed
  8. Select Tools > Hibernate > Generate Code... from the main menu.
  9. In the Database Code Generation window, select PHP to be the language of code to generate.
    select PHP language
  10. Specify the output path of code files to be generated.
    set output path
  11. Switch to the Database tab. Click Database Options at the bottom of dialog box.
    click database options
  12. Select MySQL at the database tree at the left hand side. Click on the down arrow button next to the Adapter File field to download the adapter for connecting to MySQL. Enter the hostname, database name, user name and password. Check InnoDB (with constraint). Click OK to confirm the changes.
    db configure
  13. Check Export to database. By checking this option, changes will be updated to database.
    export to db
  14. Click OK to start generation.
  15. Visit the output folder.
    generated files
  16. Deploy the files to Apache webserver.
  17. Create a PHP sample file with the following content. Place the file alongside with bootstrap.php.
    <?php
    require_once 'bootstrap.php';
    
    $conn = Doctrine_Manager::connection(DSN);
    
    $f = new farm();
    $f->name = 'My farm';
    $f->name = 'Street 1, district 1';
    $f->save();
    
    $q = Doctrine_Query::create()->from('Farm');
    $as = $q->fetchArray();
    print_r($as);
    ?>
    
  18. Start the webserver. Visit the sample page.
  19. Check MySQL to verify the changes.
    check mysql

Resources

  1. Farm Management.vpp

Rate this Article

Click on one of the stars below to rate this article from 1 (lowest) to 5 (highest).

You may be interested in

  1. Writing Effective Use Case
  2. Draw Entity Relationship Diagram (ERD)
    Tagged:
  3. UML Package Diagram
    Tagged:
  4. Produce UML Use Cases from Business Process Diagram (BPD)
  5. Oracle database design with Entity Relationship Diagram
Tags of this article:

Comments (8)

written by michele on July 20, 2011

Hi, at the 9 step if I go on language select, I have only Java but no Php....Why? How can I do?

written by Jick Yeung on July 20, 2011

Hi michele,

You are probably running the Java edition of DB Visual ARCHITECT. Please run "VP Suite Product Edition Manager.exe" in the bin folder of VP Suite installation directory and change the product edition to either Professional or PHP Edition. They both support PHP.

Best regards,
Jick Yeung

written by michele on July 20, 2011

I have already selected Professional edition, and in the select there is anyithing like php-edition...

written by Jick Yeung on July 20, 2011

Hi michele,

I am so sorry about this. I will check with our developers and get back to you as soon as possible.

Best regards,
Jick Yeung

written by Jick Yeung on July 20, 2011

Hi michele,

Please do this first:
1. Select "Tools > Object Relational Mapping > Database Configuration"
2. Select PHP for language selection.

I will also ask our team to allow direct language selection in the generation window. Sorry for any inconveniences it might have caused.

Best regards,
Jick Yeung

written by michele on July 20, 2011

I have not solved. When I go on
1. Select "Tools > Object Relational Mapping > Database Configuration"
On the Selection language I have only:
- java
- enterprise object framework

There is not Php.....What can be?
2. Select PHP for language selection.

written by michele on July 20, 2011

the solution is that php is supported for the enteriprise version and not for the professional!

written by Jick Yeung on July 21, 2011

Hi michele,

You are running VP-UML, not DB-VA. This tutorial was written for DB-VA. For DB-VA, there is no Enterprise Edition. The highest edition is Professional Edition. It supports PHP, .NET, Java.

If you are evaluating, please run the VP Suite.exe in the bin folder and install DB Visual ARCHITECT.

Best regards,
Jick Yeung

Write comment

Rating

Comment

Enter the calculation result

security code