开发者

Learning raw PHP/MySQL, are databases supposed to be confusing?

I'm fairly new to programming, and I'm teaching myself PHP and MySQL from scratch.

I'm beginning to understand ho开发者_如何学Cw databases work: you have tables, and you have unique ids for all of your subjects for your website. However, this seems rather tedious, as you don't always know how much content you want to have on your site. And the concept of relational databases seems a bit confusing.

My question is, once you reach object oriented programming with PHP and/or frameworks like codeigniter, does it simplify these concepts? I'm trying to cram raw php down right now so I can understand the foundations of the language, but it seems rather tough going so far.


The answer is no, you need to have a knowledge of database design and SQL (and a little bit about DBMS like MySQL, SQL Server, Access or whatever) to design websites that rely on databases.

However, basic database design and SQL are extremely easy to learn. And you can learn enough to get moving in a weekend (or less).

Grab a book about the DBMS you like (it looks like it's MySQL in this case) and skim through it. They generally have a chapter about database design and a chapter about SQL queries.


Working with SQL databases is a separate discipline. I disagree that it's tedious -- in fact as someone who developed procedural database code once upon a time, requiring manual creation of data structures, application of indexes, locking and typically hundreds of lines of code to do even the simplest thing, relational databases were a huge improvement and time timesaver, considering all the problems they solve. Since they are non-procedural and based on set theory, there is a learning curve but one that is well worth the effort.

With that said, one of the solutions for working with them is "Object - relational mapping" libraries, that are aimed at automating the process of interacting with a sql database, and can be used to eliminate the need for writing sql. Doctrine, Propel and Zend_db_table are a few different takes on ORM in PHP. The problem is, that ORM's are really made for people who already understand relational databases and how they are designed.

You typically have to configure the ORM, and in the case of mysql, its default "engine" named myisam doesn't support the storage of relationships between tables. ORM's often have the ability to figure out relationships using "reflection" by reading the data dictionary, but with mysql/myisam it is not possible to determine the relationships between tables, and this is something you need to configure when you setup the orm for a project. If you don't understand how to relate and join tables, and the ins and outs of database design, you will undoubtedly be very confused.

Learning the basics of SQL is not that difficult, and for most web developers it's an important skillset to have. Even with an ORM there are times when you need to drop down to raw sql for efficiency or expediency.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜