SaaS Web App in PHP/MySQL?


I have been looking for some best practices are far as developing a software as a service app (SaaS) in PHP/MySQL, but can’t seem to find anything on it. I’m surprised there are no tutorials, demo applications featuring this design pattern, especially considering the massive rush towards SaaS orientated products and general acceptance of them in business settings.

Anyone here, dtbaker or Sitebase, ever develop something like this? Or does anyone have links towards design patterns/best practices to develop software like this?



Working on one now, will sell the “lite” installable version on here, and the “full” saas version as subscription.

If you’re looking at making your own, start by making the software (eg: a CMS or Task Manager). Then add user registration / login / logout / update profile / cancel account features, and lock the software down so that only logged in users can access it. Then look at adding a payment process (probably the most complicated part), it could be a once off payment, a paypal recurring payment, etc… then disable access to the software if a user hasn’t paid. Then you can look at adding different membership levels, and locking down different parts of your application depending on the membership level they have purchased.

I think there’s a few paypal / membership subscription manager applications available here on CodeCanyon that would be very helpful.

Is that the sorta info you’re after?


My biggest concern is the use of database tables. I read that having 10000 rows in a table is better and more efficient/fast than having 100 tables with the same data… Basically, making it so that only a certain user sees a certain ‘client_ID’ field in the database I guess… The queries may get convoluted I feel like.

So, the articles table, for example, will each have a ‘client_ID’ table row attached to it. Then only allow users to access data from a given table that corresponds to their ID. I guess that’s it, heh.


That’s an easy one :slight_smile: you have a system_id field in each of your database tables.

eg: Bob, Mary and Jane are part of system_id 1, they can only see clients from system_id 1.

eg: David, Smith and Peter are part of system_id 2, they can only see mysql data from system_id 2, they cannot see Bob, Mary or Janes data because it’s part of system_id 1.

When a user logs in, do something like this to save their current system_id into a session variable:

// start processing the login with users login/password.
$sql = "SELECT * FROM `user` WHERE 
  `username` = '".mysql_real_escape_string($_POST['username'])."' 
  AND  `password` = '".mysql_real_escape_string($_POST['password'])."'";
$res = mysql_query($sql);
$client_data = mysql_fetch_assoc($res);
  // user has logged in. 
  $_SESSION['_system_id'] = $client_data['system_id'];
  echo 'Login failed or something...';

then each time you run a SQL query, add the system id onto the end.

//eg: look up client list for this system
$sql = "SELECT * FROM `client` WHERE system_id = '".$_SESSION['_system_id']."'";
$res = mysql_query($sql);
// etc...
$sql = "INSERT INTO `client` SET system_id = '".$_SESSION['_system_id']."' .....

there’s a few fun trickeries you’ll run into along the way, like sequential numbering per system (auto increment wont give sequential numbers per system), but the above should give you a good start into a multi-user single-database setup.

The way I do it? I have a simple database class that builds SQL queries, every UPDATE/INSERT/DELETE/SELECT SQL query gets the system_id automatically appended to it based on the currently logged in users system.

Hope that helps :slight_smile: