O'Reilly logo

Building a Web Application with PHP and MariaDB: A Reference Guide by Sai Srinivas Sriparasa

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Logging

The last file operation that we will work with is logging. We will begin by looking at how information can be logged to web server logs and build a simple logging library that can be used across the application. Let's begin by using the error_log function provided by PHP to log information into the web server logfiles. For this example, let's use the export action that we created in the last section to add a message that will be logged.

The following codec needs to be added to the controllers/students.php file:

public function export(){ $data = $this->model->getStudents(); $handle = fopen(ROOT_DIR.'/assets/files/students.csv', 'w+'); foreach ($data as $student) { fputcsv($handle, array($student['student_id'], $student['first_name'], $student['last_name'], ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required