Twitter Feed

Xataface Maillist

Sign up to receive the Xataface news letter with weekly updates and development tips.

 
Found 1 of 138 records in table Wiki
Now Showing 1 of 1

Current Record: How_to_build_a_PHP_MySQL_Application_with_4_lines_of_code

How to build a PHP MySQL Application with 4 lines of code

[Permalink]

The Xataface Application Framework allows you to convert your existing MySQL database into a full-fledged with as little as 4 lines of code. And it's Not a code generator.

This article is intended to spark interest in the Xataface Application Framework amongst PHP developers by showing how easy it is to set up a full-featured front-end for your MySQL database. If you are a PHP developer, surly you can identify with the situation where you've built a snazzy website with PHP and MySQL but you need to create some way the website users to administer it. I.e., you need to make an administrative back-end for your users.

You need to do this because PHP admin is too technical for your users, and it is an aweful lot of tedious work to create all of the necessary forms and lists for your users to edit the data themselves.

Features for our Application

  • Create, edit and delete records using simple web forms.
  • Browse through database and find records without any SQL.
  • Lots of great widgets for editing records including html editors, select lists, grids, checkboxes, calendars and more.
  • Sort records.
  • Export result sets as CSV or XML.
  • Fully configurable and extendable by you to implement more features.

Creating the Application

Here are 6 steps to a full-featured front-end for your database:

  1. Create a directory for your application on your webserver. Call it myapp.
  2. Download the latest version of Xataface and copy it into your application directory that we just created. (i.e. myapp/xataface.
  3. Create a configuration file named conf.ini inside your application directory (i.e. myapp/conf.ini) to store your database connection info:
    [_database]
        host=localhost
        name=mydb
        user=username
        password=mypass
    
    [_tables]
        ;; This section lists the tables to include in your application menu
        table1=Label for table 1
        table2=Label for table 2
  4. Create an .htaccess (i.e. myapp/.htaccess) file to prevent Apache from serving your conf.ini file:
    <FilesMatch "\.ini$">
    Deny from all
    </FilesMatch>
    Note: If you are not using Apache as your web server you'll need to block access to the .ini files using a different mechanism. E.g. On IIS you can create a Web.config file to block this access and place it inside your application's directory. Download a sample Web.config file here.
  5. Create an index.php file (i.e. myapp/index.php) to serve as an access point for your application:
    <?php
    // Include the Xataface API
    require_once 'xataface/dataface-public-api.php';
    
    // Initialize Xataface framework
    df_init(__FILE__, 'xataface')->display();
        // first parameter is always the same (path to the current script)
        // 2nd parameter is relative URL to xataface directory (used for CSS files and javascripts)
  6. Create a templates_c directory to store cached smarty templates or your application (i.e. myapp/templates_c, and make sure that it is writable by the webserver:

 $ mkdir templates_c
 $ chmod 777 templates_c
That's all there is to it! Point your web browser to the index.php file we just made, and check out your new app!

Screenshots of Our App

Find Form

http://media.weblite.ca/files/photos/people-find.png?max_width=400

New Record Form

http://media.weblite.ca/files/photos/people-new-record.png?max_width=400

List View

http://media.weblite.ca/files/photos/people-list.png?max_width=400

Where to go now

  1. Sign up for the Xataface mailing list to receive exclusive development tips (see the left column for a signup form).
  2. Check out the About Xataface page for more information about features and requirements.
  3. Use the Getting Started Tutorial to get started making your own application.
  4. Watch screencasts showing Xataface in action.
blog comments powered by Disqus
Powered by Xataface
(c) 2005-2017 All rights reserved