PHP construct the semantic WebCRUD operation. CreateReadUpdateDelete and CRUD are the most basic database operations, but they are also the most important operations. CRUD operations are generally the most basic database operations by using Create/Read/Update/Delete (CRUD) operations to Create, Read, Update, and Delete relational databases, 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:
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 common 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:
Similarly, note that the PREFIX row is exactly the same as the operation performed by SPARQL in the read operation. Insert into works in a similar way to SQL. However, it is URI-based, not string-based, table-based, or name-based, which allows the operation to be completed using HTTP. You must specify the mode again. Here, it is slightly easier to understand than read operations, because you can have almost any attribute, as long as it is compatible with the mode. This is the advantage of Distributed dynamic and scalable objects provided by RDF.
Delete
To a certain extent, if you want to create a file, you may need to delete it. For example, users may want to delete their accounts on your site (this is obviously a pity, they want to leave, but they may have a legitimate reason ). Listing 5 provides the SQL code for typical delete operations.
Delete from UserTable WHERE realname = "John Smith"
Now, compare the SQL-based code in listing 5 with the SPARQL-based code in listing 6.
The Create/Read/Update/Delete (CRUD) operations are the most basic database operations, but they are also the most important operations. CRUD operations usually use relational databases...