Skip to main content
Inspiring
March 2, 2016
Question

Trying to Play Catch-Up & get the Bigger Picture

  • March 2, 2016
  • 3 replies
  • 1327 views

Hi all,

Server Backend Database Access - what is best?


A bit of a layman - general question trying to get the bigger picture...

I know it's a large subject - I'm just trying to get caught up to some good CURRENT options.


Currently, I am looking into building some mobile friendly Apps/Websites that use JavaScript (json - jQuery etc.) css and html5 on the front end, And PHP?(or web services) and MySQL on the backend. These apps/sites would be for small to medium sized business for the most part.


It has been a few years since I have used PHP with MySQL database. I understand that the older original MySQL extension has been deprecated, In favor of MySQLi or PDO_MySQL extensions..


So the question is, big picture, what is the best way to interface with backend server side MySQL for this purpose? Would I use:

- web services RESTFUL?

- NODE JS?

- MySQLi?

- PDO_MySQL (Am I correct in assuming that PDO is helpful if one may need to move to another database system in the future?)

- or ???

Any links to this general subject would be helpful.

    This topic has been closed for replies.

    3 replies

    revdaveAuthor
    Inspiring
    March 6, 2016

    Thanks Rob - David & sinious,

    Thank you for all the great suggestions - most helpful.

    newbie question:

    So far I have only written code directly by hand....

    So, should I start looking into some kind of MVC - Cake PHP or something like that?

    Rob Hecker2
    Legend
    March 6, 2016

    So far I have only written code directly by hand....

    So, should I start looking into some kind of MVC - Cake PHP or something like that?

    When you use a PHP framework, you still write code by hand, though some IDEs can build the initial structure of a project for you, provide classes to perform common functions, etc.

    Working with a framework helps you lean to write good MVC code. I think it helps to first have a good handle on procedural PHP, and you should also know OO syntax. At lynda.com there is a course called "MVC frameworks for building PHP web applications." It looks at Zend, Symphony, CodeIgniter, Cake, Yii and Laravel.

    sinious
    Legend
    March 4, 2016

    I agree with everything said here and feel neither MySQLi or PDO will change from PHP for quite a long time. That said, expect anything at any time as a general web developer. Many people shortly ago would have laughed if you said the mysql_* functions would depreciate yet here we are, and they are.

    As for languages, I agree with Rob, sticking with PHP is still great if you already know it. Full web services usually end up with extra costs rather than standard shared hosting.

    Although it generally (if you pardon the looseness) overrides MySQL, MariaDB is something you should look into. It really depends on how performant you need your DB but for the future it's worth a look.

    Overall if you really expect to compete with anyone, get yourself a "setup". A scaffold that gets apps up and running extremely quickly. There is no one-and-done setup but find libraries and languages you like to develop, debug, test and deploy with and more importantly, learn how to auto-deploy with them. You want IDEs that support your setup and to stay quick, automated and efficient. I could be all grunt or scripting that compiles you but get something to take all your code and version, compile (LESS/SASS, concatenate, minify, etc), and copy to a development environment all the way to a production environment so you can deploy faster than your competition.

    revdaveAuthor
    Inspiring
    March 6, 2016

    Hi sinious,

    When you say get a set up & scaffold - can you give any suggestions where to get started?

    sinious
    Legend
    March 9, 2016

    revdave wrote:

    Hi sinious,

    When you say get a set up & scaffold - can you give any suggestions where to get started?

    Mostly what these PHP frameworks will do for you. A scaffold is just a general term for getting your project up extremely quickly by using almost a one of several "base projects" that suit what you're going to do. No one project fits all, some are heavier on front, back or both. Having a PHP framework you're used to will get you started there quickly. Having a go-to HTML/CSS framework similar to Bootstrap can speed that portion up. Choosing a JavaScript framework like Angular/etc will get you up quickly in that area.

    Soon you'll pick what suits you and your projects faster and faster. At that point you'll be up and running, knowing exactly what you need. In a nutshell, that's scaffolding. However there's entirely automated methods of doing this as well but that's a bit beyond what I'd recommend doing until you know some frameworks.

    Rob Hecker2
    Legend
    March 3, 2016
    what is the best way to interface with backend server side MySQL for this purpose?


    I don't think you need to ponder RESTful web services right now, and whether or not you end up using node.js will depend on decisions you make later.


    Even the decision to use MySQLi or PDO is not such a big deal. I only use PDO, but if I needed to switch to MySQLi for a project, I'm sure I could be up to speed in a day or so. PDO provides the ability to use bound parameters, which makes a complex SQL query easier to read. I never find myself wishing I had chosen MySQLi, but I'm sure most people who use MySQLi never find themselves wishing they had chosen PDO.


    So I think the place to start is to pick PDO or MySQLi and then start learning how to write PHP scripts that work with data. I know that some, (if not all) of David Powers' tutorials and books give examples in both PDO and MySQLi. His book "PHP Solutions" is a good place to start. There are also lots of beginner and intermediate video tutorials at lynda.com that can help familiarize you with the array of technologies used in modern web development.



    David_Powers
    Inspiring
    March 3, 2016

    Thanks for the mention, Rob. As well as PHP Solutions, I've got a course on lynda.com that covers both PDO and MySQLi. Rather than flip-flop back and forth between the two APIs, it treats them separately, but uses the same basic examples, making it easy to compare their strengths and weaknesses.

    I think the biggest argument in favour of PDO is that it has the option to use named parameters in a prepared statement. MySQLi uses only question marks as placeholders, which makes the code less easy to read.

    I had to do a quick rewrite of a couple of classes switching them from MySQLi to PDO because my hosting company had forgotten to enable MySQLi when it moved me to a new server. It was very easy to do. The only real pain point is trying to remember the names of methods. MySQLi uses bind_param(), whereas PDO uses bindParam(). A small, but crucial difference.

    Rob Hecker2
    Legend
    March 3, 2016

    Correction to my previous post:

    When I said PDO provides the ability to use bound parameters, I actually meant named parameters, making the same point as David did.