PHP WebCRUD construction

Source: Internet
Author: User
Tags web database
PHP build semantic WebCRUD operations, Read PHP build semantic WebCRUD operations, 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 usually use the Structured Query Language (StructuredQueryLanguage) in the relational database system.

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 usually completed using the Structured Query Language (SQL) in the relational database system. As the Web becomes more data-oriented, it is necessary to move from SQL-based CRUD operations to Semantic Web-based CRUD operations. Learn how to use PHP to perform CRUD operations on a semantic-based Web. Common Acronyms

API-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)

SPARQL-Simple Protocol and RDF Query Language)

Structured Query Language)

UI-User interface)

W3C-World Wide Web Consortium)

When developing Web applications, it is a standard practice to create a database structure for the logic layer and UI layer to place server code. To connect to the database, the server code needs to perform basic operations such as creating, updating, deleting, and-most importantly-reading records. Because the background databases of Web applications are usually relational databases, these CRUD operations are executed in a well-known SQL language. However, as Web development increasingly uses object-oriented programming (OOP), the model also changes.

Resource Description Framework (RDF) is an ideal method to describe the meaning of objects while retaining data. Simple Protocol and RDF Query Language (SPARQL-pronounced as "sparkle") are commonly used to Query the data, because it matches the structure of the RDF in the statement structure. Both RDF and SPARQL are Technologies in the so-called semantic Web stack (semantic Web stack.

To thoroughly apply the semantic Web concept, you can use SPARQL to apply traditional Web development technologies to RDF data. This article will show you how to use the simplified Model-View-Controller (MVC) design model, PHP server scripting language, and SPARQL connect to RDF-opposite to using SQL in relational database systems.

SQL and SPARQL CRUD operations

Prerequisites this document assumes that you have a basic understanding of SQL, PHP, and Web application development. It is also advantageous to understand semantic Web. To run the create, update, and delete commands on Semantic Web-based data, a semantic Web database that supports SPARQL/Update specifications is required.

When using SQL and SPARQL for development, you need to check 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 the SQL-based code with the SPARQL-based code shown in listing 2. The reason for using these two read operations is that they are easier to understand, implement, and describe. This is the same for SQL and SPARQL.

PREFIX foaf: PREFIX rdf: Http://www.w3.org/1999/02/22-rdf-syntax-ns#> SELECT? Uri? Name? Dob? LocationFROM Http://www.example.org/graph> WHERE {? Urirdf: type foaf: Person; foaf: name "John Smith"; foaf: birthday? Dob; foaf: location? Location .};

When comparing the two lists, your first idea is that the SPARQL version is much longer than the SQL version. This is a fact, but do not mistakenly think that SQL must be simpler and cleaner. According to the engine running, SPARQL can be distributed by calling the link data result (linked data effect. In addition, it allows a dynamic mode, because it has an object-oriented perspective that is linked to each other, which is in contrast to a strict perspective of the SQL relationship. If you want to separate relational database tables into multiple data Islands, the actually used SQL code will be much more than SPARQL-not to mention that there will be a lot of annoying JOIN descriptors in SQL.

The first two lines of SPARQL are PREFIX statements. According to the Semantic Web theory, all content-whether an object or a data graph source (also an object)-has a Uniform Resource Identifier (URI ). The PREFIX row only applies the temporary label to some URIs-In this example, it is in the Friend of a Friend and RDF modes. The advantage is that you can use the PREFIX declaration in the query in the future without using the complete URI.

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

The FROM statement describes the location where data is obtained. This is the same in SQL and SPARQL, but in SPARQL, the data source name is URI, not a string that represents a physical location in a computer or network.

The WHERE statements of the two are completely different. because SPARQL is used, you must specify the mode used to obtain data. Similarly, if you have tried to use the relational method to perform this operation, the cost is much higher than that of normal SQL: PHP, Java? Check between data sources can be performed only in programming languages or some other server languages. The operations completed by SPARQL code lines are clear, including ensuring that the data being retrieved only belongs to the Person type. SPARQL will get the name and location, and execute some pattern matching to find the correct John Smith.

Create

CRUD operations in SPARQL are generally more mysterious than read operations. However, these operations can be completed. First, the create operation inserts a new record or object into a table or chart.

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 SPARQL-based code in listing 4.

PREFIX foaf: PREFIX rdf: Http://www.w3.org/1999/02/22-rdf-syntax-ns#> INSERT INTO GRAPH (? Realname ,? Dob ,? Location ){ Rdf: Type foaf: Person; foaf: name "John Smith"; foaf: birthday <1985-01-01T00: 00: 00>; foaf: location "Bristol, UK "}

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.