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 | |
// Database configuration | |
$hostname = "your_hostname"; | |
$username = "your_username"; | |
$password = "your_password"; | |
$database = "your_database_name"; | |
try { | |
// Establish the connection using PDO |
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
Leverage guzzlehttp that abstracts a lot of oauth functionality | |
```bash | |
composer require guzzlehttp/guzzle | |
``` | |
Now, let's create the PHP script (`oauth_example.php`): | |
```php | |
<?php |
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 | |
// Define the data to be saved (replace with your actual data) | |
$data = array( | |
"name" => "John Doe", | |
"age" => 30, | |
"address" => array( | |
"street" => "123 Main St", | |
"city" => "Anytown", | |
"state" => "CA", |
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
// Breakdown of the script | |
```bash | |
composer require predis/predis | |
``` | |
1. **Update the configuration file (`config.php`):** | |
```php | |
<?php |
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 | |
// Define the API URL | |
$apiUrl = "https://jsonplaceholder.typicode.com/users"; | |
try { | |
// Create a cURL resource | |
$curl = curl_init($apiUrl); | |
// Set cURL options |
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 | |
// Define the filename | |
$filename = "file_name.txt"; | |
try { | |
// Open the file for reading | |
$file = fopen($filename, "r"); | |
// Check if the file was opened successfully |
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 | |
function sumEvenNumbers(array $numbers): int { | |
$sum = 0; | |
foreach ($numbers as $number) { | |
if ($number % 2 === 0) { | |
$sum += $number; | |
} | |
} | |
return $sum; |
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
# Configure AWS provider | |
provider "aws" { | |
region = "us-east-1" # Specify your desired region | |
} | |
# Define a resource for the VM instance | |
resource "aws_instance" "web_server" { | |
ami = "ami-0XXXXXXXXXXXXXX" # Amazon Machine Image (pre-built OS) | |
instance_type = "t2.micro" # VM instance type | |
tags = { |
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 | |
$name = filter_var($_POST['name'], FILTER_SANITIZE_STRING); // Basic sanitization | |
$sql = "SELECT * FROM users WHERE name = :name"; | |
$stmt = $db->prepare($sql); | |
$stmt->bindValue(':name', $name, PDO::PARAM_STR); | |
$stmt->execute(); | |
$result = $stmt->fetchAll(); |
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 | |
$pdo = require 'connect.php'; | |
$sql = 'SELECT author_id, name | |
FROM authors'; | |
$statement = $pdo->query($sql); | |
// get all authors |
NewerOlder