#!/usr/bin/php -q
<?php
// Include external configuration and helper files
require("/root/fm/db_con.php"); // Database connection details
// Establish a connection using MySQLi (object-oriented style)
$conn = new mysqli($host, $user, $password, $database);
// Check if the connection was successful
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Define the query to fetch leads
$query = "SELECT lead_id, phone FROM leads";
// Execute the query and check for errors
if ($result = $conn->query($query)) {
// Check if there are any rows returned
if ($result->num_rows > 0) {
// Loop through the result set and output each row
while ($row = $result->fetch_assoc()) {
// Safely output the values (HTML escaped for safety)
echo htmlspecialchars($row['lead_id']) . ", " . htmlspecialchars($row['phone']) . "\n";
}
} else {
// If no rows were found
echo "No records found.\n";
}
// Free result set to free up memory
$result->free();
} else {
// If query fails, output an error message
echo "Error executing query: " . $conn->error . "\n";
}
// Close the database connection
$conn->close();
?>