Skip to content

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

Steve Hannah edited this page Sep 2, 2016 · 2 revisions

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.

toc

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.

Table of Contents

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
  1. 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.
  1. 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)
  1. 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

Image: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

Image: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.