Created
November 26, 2024 18:52
-
-
Save rhengles/e39cbf0df74babefdeda56bb59d03fde to your computer and use it in GitHub Desktop.
PHP PDO mysql access
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$db = new PDO('mysql:host=localhost;dbname=your_database_name', 'your_username', 'your_password'); | |
$query = "INSERT INTO clients (name, email, phone) VALUES (:name, :email, :phone)"; | |
$stmt = $db->prepare($query); | |
$stmt->bindValue(':name', $args['input']['name']); | |
$stmt->bindValue(':email', $args['input']['email']); | |
$stmt->bindValue(':phone', $args['input']['phone']); | |
$stmt->execute(); | |
$clientId = $db->lastInsertId(); | |
$query = "SELECT * FROM clients WHERE id = :id"; | |
$stmt = $db->prepare($query); | |
$stmt->bindValue(':id', $clientId); | |
$stmt->execute(); | |
$client = $stmt->fetch(PDO::FETCH_ASSOC); | |
return $client; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment