I have been more of a marketing guy most of my life. However, i have recently decided to shift gear and learn programming for an ambitious start-up that i am working on. Basically, the project is based on elements of social networking elements (follow, feed, posts, notifications etc) but with a twist. I wanted to know in what order should i write the code for the infrastructure of the website. I thought ill first write down the entire database schema in MYSQL, then write all database queries with PHP, followed by making the registration page and then code entire backend of the website in PHP. Is this approach correct? I will appreciate any directions you can give me. Should i fi开发者_如何学运维rst start with the backend? What are some of the infrastructure components of a high scalable website that i will be better advised to do in C++ and not PHP?
Thanks
What you describe is the classic Waterfall Model. It almost never works, since the specifications will change because a combination of
- Changed requirements by the customer (the startup in your case)
- The customer interacting with alpha versions of the software
- You realizing something could be solved differently
Therefore, I'd recommend you implement feature by feature. Start with an empty database and a php script that just connects to that database, and implement one feature after the next.
For each feature, determine which database fields need to be added. Can you use existing database entries or restructure your database to accommodate the new tables and rows?
Then, you can do the following three steps concurrently or one after another:
- Change the model of the database objects in your code. Basic tests of the model will save you a lot of gray hairs later on.
- Add a controller to perform the new actions, or modify an existing one. Again, controller tests are essential to make sure you don't break the feature later on.
- Add or modify a view (HTML/CSS/JavaScript). You can start with the view if you're unsure about what exactly the feature should do, and present a rough (only HTML) version to the management. If the change requests start to pertain to the precise positions or colors of elements, you know you're on the right track. You can test the View manually (with different browsers) and/or with Selenium.
Neither strict MVC nor tests are required, but they simplify software development a great deal and allow you to be certain that your code will actually work in production.
PHP has got some great features for interacting with a MySQL database, and sending SQL commands to the database server.
Your database structure should attempt to take all of the data elements of your website (user details, messages, comments etc.) and break that information down into its most logical and efficient structure. This is achieved by breaking the whole lot of data into logical and discrete tables, referenced using index numbers (primary keys) or whichever fields (foreign keys) you wish to associate the tuples in each table.
Getting the database to this stage is known as 4th Normal Form (4NF) or Boyce Codd Normal Form (BCNF).
Once you have figured out the structure of your database, you can then go about querying it to either put data in some table or retrieve it, using SQL commands.
Assuming you use PHP's mysql_query ( string $query [, resource $link_identifier ] )
( http://www.php.net/manual/en/function.mysql-query.php ) you can then load the SQL data into an array, and print out the data amongst some HTML.
Once you get this going you might also want to use PHP $_SESSION
global var to keep track of any logged in users. This global uses a cookie to track authenticated users and is very useful for logging in users. You would need to implement some logging in code to match username to password, and then create the session if it's a good pass.
Hope it helps! :)
精彩评论