Skip to content

Instantly share code, notes, and snippets.

@colshrapnel
colshrapnel / multiarray_search.php
Created August 5, 2022 17:48
Measuring array_column+array_search vs. foreach
<?php
$size = 10000;
$a = [];
for ($i = 0; $i < $size; $i++) {
$a[] = ['uid' => $i, 'name' => 'Sandra Shush'.$i, 'pic_square' => 'urlof'.$i];
}
shuffle($a);
$count = 1000;
@colshrapnel
colshrapnel / pdo_review.md
Created May 19, 2020 05:13
PDO wrapper review
  1. $db = null; is NOT the way to go.

  2. Get rid of all try catch operators. They just make mo sense. If you remove them, nothing would really change, because exceptions can report themselves, no assistance required, thank you

  3. Get git of all that global stuff. It's just gross. A class has its own means to persist the state. At least use a static variable to hold the connection. Better yet, do not use that static magic at all, create a regular instance with a constructor.

  4. Do not duplicate the code. All functions contain almost identical code. Reuse the functions, Luke!

     public static function query($sqlquery, $inserts = array()){
         $stmt = static::db->prepare($sqlquery);
         $stmt->execute($inserts);
         return $stmt;
    

}

<?php
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$mysqli = mysqli_connect('127.0.0.1','root','','test');
$mysqli->query("DROP PROCEDURE IF EXISTS mysqli_crash");
$mysqli->query("CREATE PROCEDURE mysqli_crash ()
BEGIN
DECLARE col TEXT;
DECLARE res CURSOR FOR SELECT 1 from dual;
OPEN res;