gvp16 Posted June 27, 2014 Share Posted June 27, 2014 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); echo$row["field"]; 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. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/289303-your-basic-project-scripts/ Share on other sites More sharing options...
KevinM1 Posted June 27, 2014 Share Posted June 27, 2014 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. Quote Link to comment https://forums.phpfreaks.com/topic/289303-your-basic-project-scripts/#findComment-1483280 Share on other sites More sharing options...
gvp16 Posted June 30, 2014 Author Share Posted June 30, 2014 Good adivce, thank you. Quote Link to comment https://forums.phpfreaks.com/topic/289303-your-basic-project-scripts/#findComment-1483417 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.