Jump to content

Your basic project/ scripts


Recommended Posts

I have been been coding in php for about 5/6 years. While at uni I was taught the procedural way, and using all the myql_ functions to do database work. Generally speaking if you google for php coding examples you tend to come across examples using those methods which I now believe are out of date. 


In recent years I have learned some MVC, and used some frame works and open source applications (opencart, wordpress etc...)


So im just wondering, these days if you had to write a basic script to get information from a database how would you go about it? or say you were going to make a basic 5 page website with php how would you set it up?


The reason im asking these questions is because I want to get out of bad habits and using outdated methods so rather than write something like the following what would you do?


$dbh1 = mysql_connect('localhost', 'user', 'password') or die(mysql_error()); //DB connection

mysql_select_db('db_name', $dbh1);//choose correct database

$query = "SELECT * FROM table WHERE something = something";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_assoc($result);


How would you set up a basic website (content pages,contact form)?


In the past I have done something this :

request ---> index.php  (get page & content from db) ---> pass info to content.php

As i said im looking to get out of bad habits and essentially get up to scratch on modern day practices for basic projects, using a framework or CMS for such simple things seems like overkill.



Link to post
Share on other sites

Well, first, you shouldn't be using the mysql_* functions any longer. They've been deprecated and are not safe. Use either MySQLi or PDO.


Beyond that, it's basically a matter of using the right tool for the job. I would never touch WordPress, since it's absolute crap under the hood, but beyond that, if the job calls for a 3rd party app, use it. If it calls for a framework, use a modern one that you like the best (I've been using Symfony 2 a lot lately). If it's something small, just write what gets the job done. There's no set in stone correct answer, as it depends on what problem you need to solve.


Your current structure in funneling things through index.php is known as a Page Controller, and is absolutely fine for small projects. Just be sure to code defensively, and don't blindly pass along the values sent via GET to your database.

Link to post
Share on other sites


This topic is now archived and is closed to further replies.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.