![]() We’ll use this unique value as a handle to refer to the article that we want to display or edit in the CMS. So the first article will have an id of 1, the second will have an id of 2, and so on. We also add the auto_increment attribute, which tells MySQL to assign a new, unique value to an article’s id field when the article record is created. We also specify the NOT NULL attribute, which means the field can’t be empty (null) - this makes life easier for us. This lets our CMS hold up to 65,535 articles. This has a smallint unsigned (unsigned small integer) data type, which means it can hold whole numbers from 0 to 65,535. Each field holds a specific type of information about each article.įirst, we create an id field. A table consists of a number of fields (also called columns). We’re now ready to define our table structure. The stuff inside the parentheses defines the structure of the data within the table, explained below… ![]() We do this because we can’t define a table with the same name as an existing table.ĬREATE TABLE articles ( ) creates the new articles table. Let’s break the above code down a little:ĭROP TABLE IF EXISTS articles removes any existing articles table (and data - be careful!) if it already exists. ![]() ![]() It’s written in SQL, the language used to create and manipulate databases in MySQL (and most other database systems). The above code defines the schema for the articles table. Summary text NOT NULL, # A short summary of the articleĬontent mediumtext NOT NULL, # The HTML content of the article Title varchar(255) NOT NULL, # Full title of the article PublicationDate date NOT NULL, # When the article was published Id smallint unsigned NOT NULL auto_increment, A table’s schema describes the types of data that the table can hold, as well as other information about the table.Ĭreate a text file called tables.sql somewhere on your hard drive. This, as you’d imagine, holds all of the articles in the system. Our simple CMS has just one database table: articles. Step 2: Create the articles database table If you’re not sure what to do on your server, ask your tech support team for help. Some web server setups let you create databases via a web-based tool such as cPanel or Plesk (in fact sometimes this is the only way to create MySQL databases). That’s it! You’ve now created a new, empty database, into which you can put your database tables and content. If you’re working on a development server, such as your own computer, then you can use the root user for this, to save having to create a new user. username should be a user that has permission to create databases. Then enter your MySQL password when prompted. Open a terminal window and enter the following: The first thing we need to do is create a MySQL database to store our content. Ready? Grab a cup of tea, and let’s get coding! Step 1: Create the database If you don’t want to create the files yourself, simply download the finished zip file, which contains all the code files and folders. This page contains all the code for the CMS, ready for you to copy and paste into your own files. Here are the steps we’ll need to follow to create our CMS:
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |