Database Tables And Columns
OverviewObjectivesLearn the basics of creating, updating and removingtables and columns from a database.Requirements A da...
What about tables and columns? If you are using this Framework, the possibility is very high that you are using some sort ...
Defining ColumnsBefore we make a table, we have to define columns. Columns are be defined inthe format of an array where t...
Defined Columns ExampleStore in array      Auto incrementing defined              Precision is being defined            Se...
Creating a Table   Ok so we have our columns defined. Lets move onto   creating a table with the columns. In our example b...
Adding More Columns     Let’s say we forgot columns because we were distracted     by celebrity marriage that only lasted ...
Removing A ColumnOh wait, another mistake. Now you need to remove acolumn. Not a problem either. Simply pass in the tablen...
Dropping A TableSo the whole idea behind your table was a flop. Let’s getrid of the whole thing. Drop the table     1. Che...
Challenge!Below is an optional challenge to help you better understandtables and columns in ProdigyView.1. Create an table...
The Note So Obvious1. Checking if a table exist can be checked with   PVDatabase::tableExist() method.2. Checing if a colu...
Review1. Create a table using the PVDatabase::createTable()   method.2. Add a column using the PVDatabase::addColumn   met...
API ReferenceFor a better understanding of the database, visit the apiby clicking on the link below.PVDatabase            ...
Upcoming SlideShare
Loading in …5
×

Tutorial on Database Tables and Columns - PHP

795 views

Published on

Learn how to create tables and columns in multiple databases using prodigyview.

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
795
On SlideShare
0
From Embeds
0
Number of Embeds
25
Actions
Shares
0
Downloads
17
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Tutorial on Database Tables and Columns - PHP

  1. 1. Database Tables And Columns
  2. 2. OverviewObjectivesLearn the basics of creating, updating and removingtables and columns from a database.Requirements A database connection A basic understanding of the types of fields in a databaseEstimated Time8 minutes
  3. 3. What about tables and columns? If you are using this Framework, the possibility is very high that you are using some sort of database. With that database you will need to create, update and remove table and columns. By the end of this tutorial, hopefully you have the basics of creating and table columns. And because ProdigyView is database agnostic, there will work for any database that ProdigyView supports.
  4. 4. Defining ColumnsBefore we make a table, we have to define columns. Columns are be defined inthe format of an array where the key is the column name and the value is an arrayof attributes that define that column.The attributes that can be used to define a column are as follows: Auto_increment: A boolean that defines this column as a value that will be auto incrementing Unique: A boolean that defines if this column is unique. Type: The attribute with the most options, the type defines what kind of column is being created. Text, varchar, timestamp, boolean, etc. Precision: How precise the column is. So for example if you only want a varchar to be 20 characters, this would be set to 20. Default: The default value for the column.Hopefully that gives you an idea of where we headed with this example. Lets lookat a code sample next.
  5. 5. Defined Columns ExampleStore in array Auto incrementing defined Precision is being defined Set a type Set a default value
  6. 6. Creating a Table Ok so we have our columns defined. Lets move onto creating a table with the columns. In our example below, we set the primary keys to be the ‘id ‘handle ‘handle’ column and we are passing in the table name and the columns from previous slide.1. Checks if the table exist 2. Set table name 3. Set columns 4. Set primary Keys
  7. 7. Adding More Columns Let’s say we forgot columns because we were distracted by celebrity marriage that only lasted some 70 odd days and need to add some more columns. Not problem. You simply have to know the name of the table you are appending the column too, the name of the column you want to append, and the attributes that define that column. 1. Define columns 2. Iterate through columns3. Add thecolumnsindividually
  8. 8. Removing A ColumnOh wait, another mistake. Now you need to remove acolumn. Not a problem either. Simply pass in the tablename and column name to dropColumn and the columnwith be removed. 1. Check if the column exist 2. The name of the table 3. The name of the column
  9. 9. Dropping A TableSo the whole idea behind your table was a flop. Let’s getrid of the whole thing. Drop the table 1. Check if table exist 2. Drop/Delete the table
  10. 10. Challenge!Below is an optional challenge to help you better understandtables and columns in ProdigyView.1. Create an table that has columns for an auto-incrementing id, email address and column that holds the date registered.2. Make the email column unique.3. Insert an email address into the that column. Then try to enter the same email again.4. Add a Boolean column for if the user is active, set to false.5. *Add a password column that has a default value that generates a random string.
  11. 11. The Note So Obvious1. Checking if a table exist can be checked with PVDatabase::tableExist() method.2. Checing if a column exist can be checked with PVDatabase::columnExist() method.3. You can clear/truncate a table with PVDatabase::clearTableData() method.
  12. 12. Review1. Create a table using the PVDatabase::createTable() method.2. Add a column using the PVDatabase::addColumn method.3. Remove a column using PVDatabase::removeColumn() method.4. Drop a table using the PVDatabase::dropTable() method.
  13. 13. API ReferenceFor a better understanding of the database, visit the apiby clicking on the link below.PVDatabase More TutorialsFor more tutorials, please visit:http://www.prodigyview.com/tutorials www.prodigyview.com

×