// Set up database connection $username = "username"; $password = "password"; $dsn = "mysql:host=localhost;dbname=myDatabase"; $pdo = new PDO($dsn, $username, $password); // Prepare SQL statement $stmt = $pdo->prepare("INSERT INTO myTable (name, email) VALUES (?, ?)"); // Bind parameters and execute statement $name = "John Doe"; $email = "john.doe@example.com"; $stmt->bindParam(1, $name); $stmt->bindParam(2, $email); $stmt->execute();
// Set up database connection $db = new SQLite3('myDatabase.db'); // Prepare SQL statement $stmt = $db->prepare("INSERT INTO myTable (name, email) VALUES (:name, :email)"); // Bind parameters and execute statement $stmt->bindValue(':name', 'John Doe'); $stmt->bindValue(':email', 'john.doe@example.com'); $stmt->execute();Both examples demonstrate how to insert data into a database using PHP. In example 1, the PDO package library is used to connect to a MySQL database and execute an SQL statement. In example 2, the SQLite extension is used to connect to a SQLite database and execute an SQL statement.