Skip to content

Instantly share code, notes, and snippets.

View felixpenrose's full-sized avatar

Felix Penrose felixpenrose

  • Gap 360 Ltd
  • Kent, UK
View GitHub Profile
<?php
$arr = [1,2,3];
$in = str_repeat('?,', count($arr) - 1) . '?';
$sql = "SELECT * FROM table WHERE column IN ($in)";
$stm = $db->prepare($sql);
$stm->execute($arr);
$data = $stm->fetchAll();
@felixpenrose
felixpenrose / artisan log sql.php
Last active July 24, 2019 09:57
Show artisan queries executed
DB::listen(function ($query) { dump($query->sql); dump($query->bindings); dump($query->time); echo PHP_EOL . PHP_EOL; });
@felixpenrose
felixpenrose / split name into first and last.sql
Last active July 24, 2019 09:56
Split up full name field into first (inc middle) names and last name
UPDATE tbl t1,
(
SELECT
id,
TRIM(SUBSTRING(name, 1, LENGTH(name) - LENGTH(SUBSTRING_INDEX(name, ' ', -1)))) AS first_name,
SUBSTRING_INDEX(name, ' ', -1) AS last_name
FROM reviews
WHERE first_name IS NULL
) t2
@felixpenrose
felixpenrose / .gitignore
Created June 16, 2020 16:20 — forked from hieblmedia/.gitignore
Gitignore - Exclude all except specific subdirectory
#
# If all files excluded and you will include only specific sub-directories
# the parent path must matched before.
#
/**
!/.gitignore
###############################
# Un-ignore the affected subdirectory