PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
CREATE TABLE `users` ( id INT UNSIGNED NOT NULL AUTO_INCREMENT, name VARCHAR(100) NOT NULL, email VARCHAR(100) NOT NULL, PRIMARY KEY (id), UNIQUE (email) );
Copy Clear
Copy Format Clear
<?php use Carbon\Carbon; function getUser($id) { $id = intval($id); // Validate and convert to integer try { $statement = $pdo->prepare('SELECT * FROM users WHERE id = :id'); $statement->bindParam(':id', $id, PDO::PARAM_INT); $statement->execute(); $user = $statement->fetch(PDO::FETCH_ASSOC); return $user ? $user : null; } catch (PDOException $e) { // Handle database connection errors or query execution errors // You can log the error or customize the response as needed return null; } } // Example usage $userData = getUser(1); // Output the result var_dump($userData); ?>
Show:  
Copy Clear