Connecting to underlying data sources: Difference between revisions
Mr. MacKenty (talk | contribs) (Created page with "right|frame|Web Science<ref>http://www.flaticon.com/</ref> == Do you understand this? == Students will not be expected to write code to indicate how...") |
Mr. MacKenty (talk | contribs) No edit summary |
||
Line 1: | Line 1: | ||
[[file:Connection.png|right|frame|Web Science<ref>http://www.flaticon.com/</ref>]] | [[file:Connection.png|right|frame|Web Science<ref>http://www.flaticon.com/</ref>]] | ||
A webpage can be connected to a data source. A datasource can be a relational database, a flat-file data source (such as a JSON file or an XML file or just a simple plaintext file). | |||
In order to connect to an underlying datasource, we generally require three things: | |||
# The location of the database. In many cases this is localhost but there is NO REQUIREMENT that the database is on the same server as the webpage. | |||
# The credentials to authenticate (which ois usually a username and password) | |||
# The name of the database. | |||
As an example, the code below creates a connection to a database: | |||
<syntaxhighlight lang="php"> | |||
<?php | |||
// this file should be named database_inc.php | |||
$connect = mysqli_connect("localhost","YOURUSERNAME","YOURPASSWORD","YOURDATABASE"); | |||
// Check connection | |||
if (mysqli_connect_errno()) | |||
{ | |||
echo "Failed to connect to MySQL: " . mysqli_connect_error(); | |||
} | |||
?> | |||
</syntaxhighlight> | |||
== Do you understand this? == | == Do you understand this? == |
Revision as of 09:04, 26 April 2018
A webpage can be connected to a data source. A datasource can be a relational database, a flat-file data source (such as a JSON file or an XML file or just a simple plaintext file).
In order to connect to an underlying datasource, we generally require three things:
- The location of the database. In many cases this is localhost but there is NO REQUIREMENT that the database is on the same server as the webpage.
- The credentials to authenticate (which ois usually a username and password)
- The name of the database.
As an example, the code below creates a connection to a database:
<?php
// this file should be named database_inc.php
$connect = mysqli_connect("localhost","YOURUSERNAME","YOURPASSWORD","YOURDATABASE");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
?>
Do you understand this?[edit]
Students will not be expected to write code to indicate how the connection is made, but should understand the principles of connecting to an underlying data source.
Standards[edit]
These standards are used from the IB Computer Science Subject Guide[2]
- Describe how web pages can be connected to underlying data sources.
References[edit]
- ↑ http://www.flaticon.com/
- ↑ IB Diploma Programme Computer science guide (first examinations 2014). Cardiff, Wales, United Kingdom: International Baccalaureate Organization. January 2012.