function getAll($tableName) { try { $db = new PDO("mysql:host=localhost;dbname=mydatabase", "username", "password"); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $stmt = $db->prepare("SELECT * FROM $tableName"); $stmt->execute(); $rows = $stmt->fetchAll(PDO::FETCH_ASSOC); return $rows; } catch(PDOException $e) { echo "Error: " . $e->getMessage(); } }
function getAll($tableName) { $conn = new mysqli("localhost", "username", "password", "mydatabase"); if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $sql = "SELECT * FROM $tableName"; $result = $conn->query($sql); if ($result->num_rows > 0) { while($row = $result->fetch_assoc()) { $rows[] = $row; } } $conn->close(); return $rows; }In this code, we define the `getAll()` function that takes the name of the table as an argument. We establish a database connection using mysqli and then execute a SQL SELECT statement to retrieve all the records from the specified table. The `$rows` variable holds an array of all the rows retrieved, which is returned by the function. Based on the code examples provided, the package library used in this project is the database access library. Specifically, it appears that it is using either the PDO or the mysqli PHP extension library.