User Tools

Site Tools


en:web_development:databases:php

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
en:web_development:databases:php [2021/12/24 12:54]
mag
en:web_development:databases:php [2023/08/16 09:33] (current)
Line 17: Line 17:
     include('footer.php');     include('footer.php');
 ?></code> ?></code>
 +
 +==== Objects ====
 +  * Objects are an advanced data structure and we won't go into it too much here, but you'll need to understand a little bit to use the PHP database connection in this actviity.
 +  * An object is like a named array where you can access each element by name.
 +  * But an object also has functions built into. Recall that in Javascript, <html>audio</html> has built-in functions like <html>.play()</html>, <html>.paused()</html> and built-in information like <html>.paused</html>. That's because <html>audio</html> is an object.
 +  * Similarly, in PHP, an object can have both data and functions. For example, a database connection object can have information about the connection and also have functions to extract data.
 +  * Whereas you access the information in an array using <html> [] </html>, we access information and functions using <html>-></html>.
 +  * To use an abstract example, we could create an object called $table.
 +  * We could set the number of legs on the table as follows.
 +<code>$table->legs = 4;</code>
 +  * We could also move the table to another location as follows.
 +<code>$table->move($location);</code>
 +  * There is a whole school of programming based on objects (Object-oriented programming) and objects could be the subject of many classes, but this is all you need to know to use the database connection.
  
 ==== PDO Connection ==== ==== PDO Connection ====
Line 22: Line 35:
   * Copy the following code at the top of the first PHP block.   * Copy the following code at the top of the first PHP block.
 <code>    // Set up database connection <code>    // Set up database connection
-    define ('DBCONNECT', "../../pdo.php"); // database connection+    define ('DBCONNECT', "/home/dh_9m7wr9/pdo.php"); // database connection
     include_once DBCONNECT;     include_once DBCONNECT;
-    $db  = 'webdev';+    $db  = 'techschoolwebdev';
     $dsn = "mysql:host=$db_host;dbname=$db;charset=utf8mb4";     $dsn = "mysql:host=$db_host;dbname=$db;charset=utf8mb4";
     try      try 
en/web_development/databases/php.1640379261.txt.gz ยท Last modified: 2023/08/16 09:33 (external edit)