简体   繁体   English

使用git版本控件进行PHP开发

[英]Using git version control for PHP development

Is it possible to version control a PHP + MySQL + Apache project? 是否有可能对PHP + MySQL + Apache项目进行版本控制? And could it keep track of the changes in the database, like for example if I added a new table, can I possibly commit that? 它是否可以跟踪数据库中的更改,例如,如果我添加了一个新表,我可以提交吗?

Thank you. 谢谢。

It is not normal to keep databases in version control. 将数据库保留在版本控制中是不正常的。 Some developers use a sqlite database for development so that it can be checked into version control, but this can lead to issues as sqlite syntax can be different from MySQL. 一些开发人员使用sqlite数据库进行开发,以便可以将其检入版本控制,但这可能会导致问题,因为sqlite语法可能与MySQL不同。

However, you can keep your database schema and migrations source control. 但是,您可以保留数据库架构和迁移源控件。 Look at a projects such as mysql-php-migrations to get started. 查看mysql-php-migrations等项目即可开始使用。

There's a good tutorial on using PHP with Git at http://net.tutsplus.com/tutorials/other/easy-version-control-with-git/ - this should get you started. http://net.tutsplus.com/tutorials/other/easy-version-control-with-git/上有一个关于在Git上使用PHP的好教程 - 这应该可以帮助您入门。

Using Git for your PHP scripts is no problem, however tracking changes to the database is a little trickier. 使用Git作为PHP脚本是没有问题的,但跟踪对数据库的更改有点棘手。 If you have SQL scripts that create the database structure then these can be version controlled with no problems. 如果您有创建数据库结构的SQL脚本,那么这些脚本可以通过版本控制而没有任何问题。 Otherwise you could use mysqldump to output the structure to an SQL script after any changes you make: 否则,您可以使用mysqldump在进行任何更改后将结构输出到SQL脚本:

mysqldump -d -h localhost -u root -pmypassword mydatabase > dumpfile.sql 

You could use git to track PHP scripts and SQL scripts that create the necessary database structure. 您可以使用git来跟踪创建必要数据库结构的PHP脚本和SQL脚本。 Those SQL scripts could of course be version controlled and recreate the database schema at any given state. 这些SQL脚本当然可以受版本控制,并在任何给定状态下重新创建数据库模式。

Git is essentially SCM, which means Source Control. Git本质上是SCM,意思是源代码控制。 Tables in mysql are stored as binary files, so it isn't very good idea. mysql中的表存储为二进制文件,因此不是很好。

You can, however, store SQL queries which create these tables, allowing you to re-create them if you needed to. 但是,您可以存储创建这些表的SQL查询,以便在需要时重新创建它们。

As for php, it will be all good. 至于php,一切都会好的。

I recently released a really simple shell script that will help keep changes to a MySQL database under version control. 我最近发布了一个非常简单的shell脚本,它有助于在版本控制下保持对MySQL数据库的更改。

https://github.com/stevecomrie/mysql-version-control https://github.com/stevecomrie/mysql-version-control

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

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