简体   繁体   English

学习原始的PHP / MySQL,数据库应该令人困惑吗?

[英]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. 我是编程新手,我从头开始自学PHP和MySQL。

I'm beginning to understand how databases work: you have tables, and you have unique ids for all of your subjects for your website. 我开始了解数据库的工作原理:您有表,并且对于网站的所有主题都有唯一的ID。 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? 我的问题是,一旦您使用PHP和/或诸如codeigniter之类的框架进行面向对象的编程,是否可以简化这些概念? 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. 我正在尝试立即填充原始php,以便我可以理解该语言的基础,但到目前为止,这似乎很难。

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. 答案是否定的,您需要具备数据库设计和SQL知识(以及一些有关DBMS的知识,例如MySQL,SQL Server,Access等),才能设计依赖数据库的网站。

However, basic database design and SQL are extremely easy to learn. 但是,基本的数据库设计和SQL非常容易学习。 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. 拿起一本有关您喜欢的DBMS的书(在这种情况下,它看起来像是MySQL)并略读一遍。 They generally have a chapter about database design and a chapter about SQL queries. 他们通常有一章关于数据库设计,一章关于SQL查询。

Working with SQL databases is a separate discipline. 使用SQL数据库是一门独立的学科。 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. 话虽这么说,使用它们的解决方案之一是“对象-关系映射”库,该库旨在自动化与sql数据库的交互过程,并且可用于消除编写sql的需要。 Doctrine, Propel and Zend_db_table are a few different takes on ORM in PHP. Doctrine,Propel和Zend_db_table是PHP中ORM的一些不同用法。 The problem is, that ORM's are really made for people who already understand relational databases and how they are designed. 问题是,ORM确实是为已经了解关系数据库及其设计方式的人们制作的。

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,在mysql的情况下,其默认名称为myisam的“引擎”不支持存储表之间的关系。 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. ORM通常能够通过读取数据字典来使用“反射”来找出关系,但是对于mysql / myisam而言,无法确定表之间的关系,而这是在为数据库设置orm时需要配置的项目。 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. 学习SQL的基础并不是那么困难,对于大多数Web开发人员来说,这是一项重要的技能。 Even with an ORM there are times when you need to drop down to raw sql for efficiency or expediency. 即使使用ORM,有时也需要降低原始sql的效率或权宜性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM