Giter Club home page Giter Club logo

test's Introduction

test

index_orig.php - Original code. index_new.php - rewritten code within a single file.

The rest of the files are MVC solution.

This code is supposed to get page title from a database and show it within a title tag. Then it should check for a certain get-parameter and if any - retrieve the data and represent it as an html list.

Weaknesses:

  1. mysql_* functions are deprecated since php5.5. PHP 5.4 hasn't been receiving security updates since September 2015 afaik.
  2. Db connection establishment occurs only if get-parameter has been passed. But we are trying to reach the data out from db before - into getPageTitle(), so it will fail.
  3. We should handle possible errors related to database connection.
  4. "if ($_GET['some_parameter'])" causes a PHP notice. We should use either isset() or !empty() instead.
  5. Seems we are going to show
      tag anyway. But we need it only if we have some
    • 's to display.

And basically handling html layout and logic within a single file is a bad practice. I'd suggest to use MVC approach (the simplest one in particular). I haven't done any routing in the context of this task.

Pros comparing to the original code:

  • We ensure exception handling so we don't need to check for a proper db connection everywhere we use it.
  • And it is test-friendly as well.
  • We use PDO which makes us more flexible in terms of database driver.

test's People

Contributors

klimp-drupal avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.