A guide on the basics for using PDO PHP for MySQL with pre-prepared statements.
This file contains 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=127.0.0.1;dbname=test;charset=utf8mb4", 'root', ''); | |
$db->beginTransaction(); | |
$insert = $db->prepare("INSERT IGNORE INTO `objects` (`id`, `color`) VALUES (?, ?);"); | |
$test_array = ['Red', 'Orange', 'Pink', 'Lime', 'Yellow', 'Gold', 'Green', 'Blue', 'Purple', 'Maroon', 'Silver', 'Aqua']; | |
$id = 0; | |
foreach ($test_array as $c) { |
This file contains 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 | |
$backup_config = array( | |
'DB_HOST' => '127.0.0.1',////Database hostname | |
'DB_NAME' => 'test_db',//Database name to backup | |
'DB_USERNAME' => 'root',//Database account username | |
'DB_PASSWORD' => '',//Database account password | |
'INCLUDE_DROP_TABLE' => false,//Include DROP TABLE IF EXISTS | |
'SAVE_DIR' => '',//Folder to save file in | |
'SAVE_AS' => 'test_db-',//Prepend filename | |
'APPEND_DATE_FORMAT' => 'Y-m-d-H-i',//Append date to file name |
This file contains 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 | |
//Config options for chart data | |
$player_id = 202331;//Paul George player id | |
$season_type = 2;//2 is regular season, 3 is playoffs | |
//Design / Display options: | |
$bootstrap_css_url = 'https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.6.0/css/bootstrap.min.css'; | |
$chartjs_js_url = 'https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.4/Chart.min.js'; | |
$background_color = '#7bbbbb';//Page background color |
This file contains 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 | |
if (session_status() == PHP_SESSION_NONE) { | |
session_start();//Start session if none exists/already started | |
} | |
if (isset($_POST['ajax_call']) || isset($_GET['ajax_call'])) { | |
$headers = getallheaders(); | |
if (isset($headers['token'])) { | |
$header_token = $headers['token']; | |
if ($header_token != $_SESSION['token']) { |
This file contains 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
<article> | |
<div class="container"> | |
<div class="row"> | |
<div class="col-lg-8 col-md-10 mx-auto"> | |
<div class="post-heading"> | |
<h1>Man must explore, and this is exploration at its greatest</h1> | |
<h2 class="subheading">Problems look mighty small from 150 miles up</h2> | |
<span class="meta">Posted by | |
<a href="#">Boss</a> | |
on January 5, 2021</span> |
This file contains 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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> | |
<meta name="description" content=""> | |
<meta name="author" content=""> |
This file contains 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 | |
$params = $_GET; | |
$count = 0; | |
foreach ($params as $key => $value) { | |
if ($count === 0) { | |
echo "?{$key}={$value}"; | |
} else { | |
echo "&{$key}={$value}"; | |
} | |
//echo "$key : $value<br>"; |
This file contains 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
<div class="container"> | |
<div class="row"> | |
<div class="col-lg-12"> | |
<div class="card"> | |
<div class="card-header"><h2 class="text-center">Input based on select</h2></div> | |
<div class="card-body"><p class="lead text-center">Example of a select form with an input appearing | |
based on the selection.</p> | |
<p class="text-center">Change the select input below to see the changes</p> | |
<form id="submit-form" method="post" action="" role="form"> | |
<div class="row"> |
This file contains 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 ageForDate(string $dob, string $date = 'today', bool $years_only = true): string | |
{ | |
$from = new DateTime($dob); | |
$to = new DateTime($date); | |
$interval = $from->diff($to); | |
if ($years_only) { | |
return $from->diff($to)->y;//years | |
} else { | |
return $from->diff($to)->y . '.' . $from->diff($to)->m;//years.months |