write_on_file: file = $file,
\n"; echo "name = $this->name,
\n"; echo "surname = $this->surname,
\n"; echo "serial_number = $this->serial_number,
\n"; echo "email = $this->email,
\n"; echo "phone = $this->phone,
\n"; echo "laurea_degree = $this->laurea_degree,
\n"; } /* 1) open the file $file in append mode, 2) write the student data into the file $file and then 3) close the file $file. */ $handle = fopen($file, "a"); fwrite($handle,"$this->name\t$this->surname\t$this->serial_number\t$this->email\t$this->phone\t$this->laurea_degree\n"); fclose($handle); } /* Declare a public (by default) method named "write_on_database": */ function write_on_database($database,$table) { /* By using the following variables I am referring to those variables whose scope is global (defined outside the function). On the other hand, I give $database and $table as input to the function. */ global $mysql_host, $mysql_user, $mysql_password; if (DEBUG){ echo "write_on_database: mysql_host = $mysql_host, mysql_user = $mysql_user, mysql_password = $mysql_password
\n"; echo "write_on_database: database = $database, table = $table
\n"; echo "writeing the following data
\n"; echo "name = $this->name,
\n"; echo "surname = $this->surname,
\n"; echo "serial_number = $this->serial_number,
\n"; echo "email = $this->email,
\n"; echo "phone = $this->phone,
\n"; echo "laurea_degree = $this->laurea_degree.
\n"; } // Connecting to the MySQL server: $link = mysql_connect($mysql_host, $mysql_user, $mysql_password) or die('Could not connect: ' . mysql_error()); if (DEBUG){ echo "Connected successfully to the server !!
\n"; } // Selecting the database: mysql_select_db($database) or die('Could not select database'); if (DEBUG){ echo "Successfully selected the database !!
\n"; } // If $table doesn't exists then create one with 7 fields (i. e., columns) as follows: // first create the SQL query, $query = "CREATE TABLE IF NOT EXISTS `$table` ( `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY, `when` TIMESTAMP DEFAULT NOW(), `name` VARCHAR(30), `surname` VARCHAR(30), `serial_number` INT(6) UNSIGNED, `email` VARCHAR(40), `phone` CHAR(15), `laurea_degree` VARCHAR(100) );"; if (DEBUG){ echo "".$query."
\n"; } // then submit the query to the selected $database. mysql_query($query) or die('Query failed: ' . mysql_error()); // Insert data into $table. Note that the first two field are computed (see $table definition just above). // Again, first create the SQL query, $query = "INSERT INTO `$table` (`name`,`surname`,`serial_number`,`email`,`phone`,`laurea_degree`) VALUES ( '$this->name', '$this->surname', $this->serial_number, '$this->email', '$this->phone', '$this->laurea_degree' );"; if (DEBUG){ echo "".$query."
\n"; } // then submit the query to the selected $database. mysql_query($query) or die('Query failed: ' . mysql_error()); // Close the connection to the MySQL server. mysql_close($link); } /* Declare a public (by default) method named "write_in_output": */ function write_in_output() { /* Echo the student properties. To be continued. */ echo "Name: $this->name,Connected and selected successfully the database !!
\n"; } // Getting all the table data with the following SQL query. // First create the SQL query, $query = "SELECT * FROM $table ORDER BY name DESC"; if (DEBUG){ echo "".$query."
\n"; } // then submit the query to the selected $database to get the data (into $result). $result = mysql_query($query) or die('Query failed: ' . mysql_error()); // Printing results in an HTML table: echo "$key | \n"; } echo "\t
---|
$col_value | \n"; } echo "\t
$col_value | \n"; } echo "\t