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:
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: