MySQL Exception & DatabaseJamshid HashimiTrainer, Cresco Solutionhttp://www.jamshidhashimi.comjamshid@netlinks.af@jamshidh...
Agenda• Error• Exception• About Database & Hierarchical Model• Specialization, Generalization & Aggregation• Database Norm...
Error• Error handling is important– First, it lets the user know, in a relatively friendlymanner, that something has gone ...
Error• mysqli_connect_errno()– Returns the error code from the last connection error• mysqli_connect_error()– Returns the ...
Exception• With PHP 5 came a new object oriented wayof dealing with errors.• Exception handling is used to change thenorma...
Exception$arr = array(23,44,55,77,88,99);try{if(in_array(4,$arr)){echo "FOUND";}else{throw new exception("4 not found in t...
Database• A database is an organized collection ofinformation. Small businesses can use databasesin a number of different ...
Hierarchical Database Model• IBM introduced the first generation ofdatabase technology, known as hierarchical,when it inst...
Hierarchical Database Model
Hierarchical Database Model• The structure allows representing information usingparent/child relationships: each parent ca...
Hierarchical Database Model• "Hierarchical database systems are difficult touse. They require application developers topro...
Aggregation• Aggregation– The aggregation is an abstraction concept, whichis used to build higher-level object (object as ...
Aggregation• The aggregation abstraction allows thedesigner to either decompose objects bybreaking them into more detailed...
Generalization• Generalization is another powerfulabstraction. Generalization allows entities ofdifferent types to be cons...
Specialization• Categorizing the entities (or objects) in the setaccording to their roles in a relationship, iscalled spec...
Specialization• Clerk, manager, and programmer– super-class Employee’• An entity may have several specializations.– EMPLOY...
Database Normalization• Normalization is the process of efficientlyorganizing data in a database.• There are two goals of ...
Database Normalization• First Normal Form (1NF): First normal form(1NF) sets the very basic rules for an organizeddatabase...
Database Normalization
Database Normalization
Database Normalization• Second Normal Form (2NF): Second normalform (2NF) further addresses the concept ofremoving duplica...
Database Normalization
Database Normalization
Database Normalization• Third normal form (3NF) goes one large stepfurther:– Meet all the requirements of the second norma...
Database Normalization
Database Normalization
Database Normalization• The Boyce-Codd Normal Form, also referred toas the "third and half (3.5) normal form", addsone mor...
Database Normalization• In order to convert a table to BCNF, we must:1. Find and remove the overlapping candidatekeys. Pla...
• Suppose we have five columns in a table.Primary KeyDatabase Normalization
• but column C can determine the value of columnB.• In other words, the value of Column B isdetermined by the Column C the...
• To convert this table into BCNF, we need todivide into two tables.• The table1 contains the following columns.• where pr...
• And table2 will contain the two columns.• where C will be the primary key.• Thus every table satisfying the 3NF conditio...
• Consider the following non-BCNF table:The candidate keys of the table are:• {Person, Shop Type}• {Person, Nearest Shop}D...
Why it is not BCNF?• The violation of BCNF means that the table is subject toanomalies. For example, Eagle Eye might have ...
How to convert itninto BCNF?Database Normalization
• After normalizationCandidate keys are {person, shop}and{shop},respectively.Database Normalization
Database Normalization• Fourth Normal Form (4NF): Finally, fourthnormal form (4NF) has one additionalrequirement:– Meet al...
Database Normalization
Database Normalization
Relationship• One-to-one relationships: Occur when each entry in the first table has one, andonly one, counterpart in the ...
ASSIGNMENT
QUESTIONS?
Upcoming SlideShare
Loading in …5
×

Exception & Database

413 views
309 views

Published on

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

  • Be the first to like this

No Downloads
Views
Total views
413
On SlideShare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
22
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Exception & Database

  1. 1. MySQL Exception & DatabaseJamshid HashimiTrainer, Cresco Solutionhttp://www.jamshidhashimi.comjamshid@netlinks.af@jamshidhashimiajamshidhashimiAfghanistan WorkforceDevelopment Program
  2. 2. Agenda• Error• Exception• About Database & Hierarchical Model• Specialization, Generalization & Aggregation• Database Normalization• Relationships
  3. 3. Error• Error handling is important– First, it lets the user know, in a relatively friendlymanner, that something has gone wrong and thatthey should contact the technical supportdepartment or that someone from tech supporthas been notified.– Second it allows the programmer to put in someniceties to aid in the debugging of issues.
  4. 4. Error• mysqli_connect_errno()– Returns the error code from the last connection error• mysqli_connect_error()– Returns the error description from the last connection error• mysqli_errno()– Returns the last error code for the most recent function call• mysqli_error_list()– Returns a list of errors for the most recent function call• mysqli_error()– Returns the last error description for the most recent functioncall
  5. 5. Exception• With PHP 5 came a new object oriented wayof dealing with errors.• Exception handling is used to change thenormal flow of the code execution if aspecified error (exceptional) condition occurs.This condition is called an exception.
  6. 6. Exception$arr = array(23,44,55,77,88,99);try{if(in_array(4,$arr)){echo "FOUND";}else{throw new exception("4 not found in the array");}if(is_array($arr)){echo "TRUE";}else{throw new customException("It is not an array");}}catch(exception $e){echo "Error occured in the file: ".$e->getFile()." and in line".$e->getLine()." with a message: ".$e->getMessage();}catch(customException $e){echo $e->errorMessage();}
  7. 7. Database• A database is an organized collection ofinformation. Small businesses can use databasesin a number of different ways. A database canhelp you organize information about yourcustomers and clients. A database can containinformation about your product inventory. Adatabase can track sales, expenses and otherfinancial information.• In a database an entity type is the equivalent of atable. Each individual record is represented as arow, and each attribute as a column.
  8. 8. Hierarchical Database Model• IBM introduced the first generation ofdatabase technology, known as hierarchical,when it installed IMS (InformationManagement System ) in its mainframecomputers in the mid-1960s. This technologywas upgraded in the mid-1970s to networkdatabase technology. Both hierarchical andnetwork databases are often described by theterm hierarchical database.
  9. 9. Hierarchical Database Model
  10. 10. Hierarchical Database Model• The structure allows representing information usingparent/child relationships: each parent can have manychildren, but each child has only one parent (also known asa 1-to-many relationship). All attributes of a specific recordare listed under an entity type.• Currently the most widely used hierarchical databases areIMS developed by IBM and Windows Registry by Microsoft.• Mother–child relationship: Child may only have one motherbut a mother can have multiple children. Mothers andchildren are tied together by links called "pointers". Amother will have a list of pointers to each of her children.
  11. 11. Hierarchical Database Model• "Hierarchical database systems are difficult touse. They require application developers toprogram navigation through the connectedrecords [...]• "They also require developers to predict allpossible access patterns in advance anddesign the database accordingly. A databaseaccess pattern that is not included in thedesign becomes very difficult and inefficient."
  12. 12. Aggregation• Aggregation– The aggregation is an abstraction concept, whichis used to build higher-level object (object as awhole) from its components. For example, acomputer is built by using various relatedcomponents.
  13. 13. Aggregation• The aggregation abstraction allows thedesigner to either decompose objects bybreaking them into more detailed componentsor to aggregate objects, grouping themtogether into higher-level objects.Decomposition is simply the. opposite processto aggregation. Both processes are consideredthe part of the aggregation abstraction.
  14. 14. Generalization• Generalization is another powerfulabstraction. Generalization allows entities ofdifferent types to be considered as examplesof a higher level set. It means that combiningdifferent types of entities (or objects) into ahigher-level set or in more general entitytypes is called generalization.– For example, electronic device is a more generalentity type of electronic objects like computer, TVset etc.
  15. 15. Specialization• Categorizing the entities (or objects) in the setaccording to their roles in a relationship, iscalled specialization. Specialization is theprocess of defining a set of subclasses of anentity. The set of subclasses that form aspecialization are defined on the basis ofsome distinguishing characteristics of theentities in the super-class.
  16. 16. Specialization• Clerk, manager, and programmer– super-class Employee’• An entity may have several specializations.– EMPLOYEE• Permanent-Employee• Temporary-Employee
  17. 17. Database Normalization• Normalization is the process of efficientlyorganizing data in a database.• There are two goals of the normalizationprocess:– Eliminating redundant data (for example, storingthe same data in more than one table)– Ensuring data dependencies make sense (onlystoring related data in a table).
  18. 18. Database Normalization• First Normal Form (1NF): First normal form(1NF) sets the very basic rules for an organizeddatabase:– Eliminate duplicative columns from the sametable.– Create separate tables for each group of relateddata and identify each row with a unique columnor set of columns (the primary key).
  19. 19. Database Normalization
  20. 20. Database Normalization
  21. 21. Database Normalization• Second Normal Form (2NF): Second normalform (2NF) further addresses the concept ofremoving duplicative data:– Meet all the requirements of the first normalform.– Remove subsets of data that apply to multiplerows of a table and place them in separate tables.– Create relationships between these new tablesand their predecessors through the use of foreignkeys.
  22. 22. Database Normalization
  23. 23. Database Normalization
  24. 24. Database Normalization• Third normal form (3NF) goes one large stepfurther:– Meet all the requirements of the second normalform.– There is no transitive functional dependency
  25. 25. Database Normalization
  26. 26. Database Normalization
  27. 27. Database Normalization• The Boyce-Codd Normal Form, also referred toas the "third and half (3.5) normal form", addsone more requirement:– Meet all the requirements of the third normalform.– Every determinant must be a candidate key.
  28. 28. Database Normalization• In order to convert a table to BCNF, we must:1. Find and remove the overlapping candidatekeys. Place the part of the candidate key andthe attribute it is functionally dependent on,in a different table.2. Group the remaining items into a table.
  29. 29. • Suppose we have five columns in a table.Primary KeyDatabase Normalization
  30. 30. • but column C can determine the value of columnB.• In other words, the value of Column B isdetermined by the Column C then this table cannot be in the Boyce - Codd Normal Form.Database Normalization
  31. 31. • To convert this table into BCNF, we need todivide into two tables.• The table1 contains the following columns.• where primary key is the combination of thecolumn A and BDatabase Normalization
  32. 32. • And table2 will contain the two columns.• where C will be the primary key.• Thus every table satisfying the 3NF conditioncannot be said to be in BCNF normal form but atable in BCNF will always be in 3NF form.Database Normalization
  33. 33. • Consider the following non-BCNF table:The candidate keys of the table are:• {Person, Shop Type}• {Person, Nearest Shop}Database Normalization
  34. 34. Why it is not BCNF?• The violation of BCNF means that the table is subject toanomalies. For example, Eagle Eye might have its ShopType changed to "Optometrist" on its "Fuller" recordwhile retaining the Shop Type "Optician" on its"Davidson" record.Database Normalization
  35. 35. How to convert itninto BCNF?Database Normalization
  36. 36. • After normalizationCandidate keys are {person, shop}and{shop},respectively.Database Normalization
  37. 37. Database Normalization• Fourth Normal Form (4NF): Finally, fourthnormal form (4NF) has one additionalrequirement:– Meet all the requirements of the third normalform.– A relation is in 4NF if it has no multi-valueddependencies.
  38. 38. Database Normalization
  39. 39. Database Normalization
  40. 40. Relationship• One-to-one relationships: Occur when each entry in the first table has one, andonly one, counterpart in the second table.– One-to-one relationships are rarely used because it is often more efficient to simply put all ofthe information in a single table.• One-to-many relationships: Are the most common type of database relationship.They occur when each record in the first table corresponds to one or more recordsin the second table but each record in the second table corresponds to only onerecord in the first table.– For example, the relationship between a Teachers table and a Students table in an elementaryschool database would likely be a one-to-many relationship, because each student has onlyone teacher, but each teacher may have multiple students.• Many-to-many relationships: Occur when each record in the first tablecorresponds to one or more records in the second table and each record in thesecond table corresponds to one or more records in the first table.– For example, the relationship between a Teachers and a Courses table would likely be many-to-many because each teacher may instruct more than one course and each course may havemore than one instructor.
  41. 41. ASSIGNMENT
  42. 42. QUESTIONS?

×