11.07.2015 Views

AJAX and PHP

AJAX and PHP

AJAX and PHP

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 3Working with MySQLA back-end data store is necessary when you implement any kind of application that is expected togenerate some useful dynamic output. The most common ways to store the application's data arein Relational Database Management Systems (RDBMS), which are very powerful tools that canstore <strong>and</strong> manage our data.Much like the other ingredients, the database is not a part of <strong>AJAX</strong>, but it's not likely that you'll beable to build real web applications without a database to support them. In this book, we'll presentsimple applications that don't have impressive data needs, but still require a database nevertheless.For the examples in this book we chose MySQL, which is a very popular database among <strong>PHP</strong>developers. However, because the database functionality is very generic, you can port it to otherdatabase systems with very little effort.To build an application that uses databases you need to know the basics of:1. Creating database tables that can hold your data2. Writing SQL queries to manipulate that data3. Connecting to your MySQL database using <strong>PHP</strong> code4. Sending SQL queries to the database, <strong>and</strong> retrieving the resultsOnce again, we'll only be able to cover the very basics of working with <strong>PHP</strong> <strong>and</strong> MySQLdatabases here. The <strong>PHP</strong> <strong>and</strong> MySQL online free manuals are quite well written, so youmay find them useful along the way.Creating Database TablesTo create a data table you need to know the basic concepts of the structure of a relational database.A data table is made up of columns (fields), <strong>and</strong> rows (records). When creating a data table youneed to define its fields, which can have various properties. Here we will discuss:• Primary Keys• Data Types• NULL <strong>and</strong> NOT NULL columns• Default column values• auto_increment columns• IndexesThe primary key is a special column (or set of columns) in a table that makes each row uniquelyidentifiable. The primary key column doesn't allow repeating values, so every value will beunique. When the primary key is formed of more than one column, then the set of columns (<strong>and</strong>not each column separately) must be unique. Technically, PRIMARY KEY is a constraint (a rule) thatyou apply to a column, but for convenience, when saying "primary key", we usually refer to thecolumn that has the PRIMARY KEY constraint. When creating a PRIMARY KEY constraint, a uniqueindex is also created on that column, significantly improving searching performance.101

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!