What is the process for extracting system information from Unix and saving it to an external file for import into a MySQL database using PHP?
To extract system information from Unix and save it to an external file for import into a MySQL database using PHP, you can use shell commands to gather the information and write it to a file. Then, you can use PHP to read the file, parse the data, and insert it into the MySQL database.
<?php
// Execute shell command to gather system information and save it to a file
$system_info = shell_exec('uname -a && df -h && top -n 1');
file_put_contents('system_info.txt', $system_info);
// Read the saved file and parse the data
$system_data = file_get_contents('system_info.txt');
// Connect to MySQL database
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";
$conn = new mysqli($servername, $username, $password, $dbname);
// Insert system information into MySQL database
$sql = "INSERT INTO system_info (info) VALUES ('$system_data')";
$conn->query($sql);
// Close database connection
$conn->close();
?>
Keywords
Related Questions
- What are the potential pitfalls of using htmlentities versus htmlspecialchars for encoding UTF-8 characters in PHP?
- What is the best practice for sorting topics by the date of the latest post in a PHP forum?
- What are some best practices for implementing a secure REST solution with PHP, excluding the Slim framework?