PHP Build Semantic Web CRUD Operations _php Tutorial

Source: Internet
Author: User
Tags php server web database
Create, read, update, and delete (Create/read/update/delete,crud) operations are the most basic database operations, but they are also the most important operations. CRUD operations are typically done using a Structured Query Language (structured Query language,sql) in a relational database system. As the Web becomes more data-oriented, it needs to move from a SQL-based crud operation to a semantic Web-based crud operation. Learn how to use PHP to perform CRUD operations through a semantic-based Web.

Common abbreviations

api-application Programming Interface (application programming Interface)

crud-Create/read/update/delete (Create/read/update/delete)

http-Hypertext Transfer Protocol (hypertext Transfer Protocol)

mvc-mode-View-controller (Model-view-controller)

oop-Object-Oriented programming (Object-oriented programming)

rdf-Resource Description Framework (Resource Description Framework)

sparql-simple protocol and RDF query Language (PROTOCOL and RDF queries Language)

sql-structured querying language (structured query Language)

ui-UI (User interface)

w3c-World Wide Web Consortium

Creating a database structure for placing server-side code for the logical and UI tiers is a standard practice when developing WEB applications. To connect to a database, server-side code needs to perform some basic creation, update, delete, and-most importantly-read records. Because the Web application's back-end database is usually a relational database, these CRUD operations are performed using well-known SQL languages. However, as WEB development is increasingly being used in object-oriented programming (OOP), the model has changed with it.

The Resource Description Framework (Resource Description FRAMEWORK,RDF) is an ideal way to describe the object while preserving the meaning of the data. The simple protocol and RDF query Language (PROTOCOL and RDF language,sparql-pronunciation as "sparkle") is the language that is typically used for querying against that data because it matches the structure of the RDF itself on the statement composition. Both RDF and SPARQL are technologies in the so-called Semantic Web stack (Semantic Web stack).

To apply the semantic Web concept thoroughly, you can use SPARQL to apply traditional Web development techniques to RDF data. This article will show you how to use the simplified schema-view-controller (MODEL-VIEW-CONTROLLER,MVC) design model, the PHP server-side scripting language, and SPARQL to connect to rdf-instead of using SQL in a relational database system.

SQL and SPARQL CRUD operations

Prerequisite

This article assumes that you have a basic understanding of SQL, PHP, and WEB application development. Understanding the semantic Web is also beneficial. To run the Create, update, and delete commands on a semantic web-based data, you need a semantic Web database that supports the Sparql/update specification.

When you use SQL and SPARQL for development, you need to look at the similarities and differences between CRUD operations. Listing 1 shows the SQL code for the read operation.

Select Realname, DOB, locationfrom usertable WHERE realname = "John Smith";

Compare this SQL-based code with the SPARQL-based code shown in Listing 2. The reason for using these two read operations is that they are easiest to understand, implement, and explain. This is the same for both SQL and SPARQL.

PREFIX FOAF:

When you compare two lists, your first thought is likely to be that the SPARQL version is significantly longer than the SQL version. This is true, but don't mistake SQL for simplicity and cleanliness. Depending on the engine being run, the SPARQL can be distributed all through the content known as linked data results (linked. Effect). In addition, it allows for dynamic mode because it has an object-oriented perspective that is linked to each other, and is contrasted with a strict SQL relationship perspective. If you want to separate relational database tables into many data silos, you're actually using a lot more SQL code lines than SPARQL-not to mention a lot of nasty JOIN descriptors in SQL.

The first two lines of SPARQL are PREFIX declarations. According to the semantic Web theory, all content-whether object or data graph source (also an object)-has a Uniform Resource identifier (Uniform Resource Identifier,uri). The PREFIX line only applies temporary tags to some URIs-in this case, friend of a friend and RDF pattern. The advantage is that you can later use the PREFIX declaration in your query without having to use the full URI.

The next line of the SPARQL code describes the query request. This statement is essentially the same as the SQL statement, unlike the additional request for the URI. Note the use of the question mark (?) is to indicate that the term is a variable.

The FROM statement describes where to get the data. This is the same in SQL and SPARQL, except that in SPARQL, the data source name is a URI, not a string representing a physical location on the computer or network.

The WHERE statement is completely different, because using SPARQL, you must specify the pattern that is used to get the data. Similarly, if you try to do this using a relational method, it will cost more than normal SQL: you need to use PHP, the Java™ programming language, or some other server-side language to perform checks between data sources. The SPARQL line of code completes the operation quite clearly, which includes ensuring that the data being retrieved belongs to the person type only. SPARQL will get the name and location while performing some pattern matching to find the correct John Smith.

Create

CRUD operations in SPARQL are often more cryptic than read operations. However, you can complete these operations. First, the Create operation inserts a new record or object into the table or diagram.

INSERT into Usertable (Realname, DOB, location) VALUES ("John Smith", "1985-01-01", "Bristol, UK");

Now, compare the SQL-based code in Listing 3 with the create operation in the SPARQL-based code in Listing 4.

PREFIX FOAF:

Also, note that the PREFIX line is exactly the same as the operation performed in the read operation with SPARQL. INSERT into works like SQL, but again, this is URI-based, not string-based, table-and name-based, which allows the operation to be done using HTTP. You must specify the pattern again. Here, it is slightly easier to understand than in a read operation, because you can have almost any property as long as it is compatible with the schema. This is the benefit of the distributed, dynamically extensible object provided by RDF.

Delete

To a certain extent, if you want to create it, you will probably need to delete it. For example, users may want to delete their accounts in your site (which is obviously a pity thing that they want to leave, but they may have legitimate reasons). Listing 5 provides the SQL code for a typical delete operation.

DELETE from usertable WHERE realname = "John Smith"

Now, compare the SQL-based code in Listing 5 with the SPARQL-based code in Listing 6.

http://www.bkjia.com/PHPjc/752064.html www.bkjia.com true http://www.bkjia.com/PHPjc/752064.html techarticle Create, read, update, and delete (Create/read/update/delete,crud) operations are the most basic database operations, but they are also the most important operations. CRUD operations are typically using relational databases ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.