function pdoExists($table, $field, $value) { global $pdo, $query_factory; $select = $query_factory->newSelect(); $select->cols(array('*'))->from($table)->where($field . ' = :value')->bindValue('value', $value)->limit(1); $result = pdoSelect($select); if (count($result)) { return $result[0]['id']; } else { return false; } }
<?php error_reporting(-1); ini_set('display_errors', 'On'); require 'vendor/autoload.php'; require 'time_since.php'; require 'db/aurasql.php'; require 'get_incidents.php'; $incidents = getIncidents(); foreach ($incidents as $incident) { $select = $query_factory->newSelect(); $select->cols(array('id', 'status'))->from('incidents')->where('incident_id = :incident_id')->bindValue('incident_id', $incident['incident_id'])->limit(1); $data = pdoSelect($select); if (count($data)) { $data = $data[0]; if ($incident['status'] !== $data['status']) { $update_data = array('status' => $incident['status'], 'duration' => $incident['duration']); if ($incident['status'] === 'resolved') { $update_data['resolved'] = $incident['resolved']; } d(pdoUpdate('incidents', $data['id'], $update_data)); } } else { d(pdoInsert('incidents', $incident)); } // d($data); }
<?php /** * Created by PhpStorm. * User: Ben * Date: 8/13/2015 * Time: 7:05 PM */ require_once 'vendor/autoload.php'; $proteinHeaderArray = array('title', 'description', 'rating', 'mainIngredient', 'servings', 'pricePerServing', 'percentOff', 'totalPrice', 'bodyBuildingPrice'); $sql = "SELECT title, description, details, rating, supportedGoal, mainIngredient, servings, pricePerServing, percentOff, totalPrice, bodyBuildingPrice\n FROM protein"; $protein = pdoSelect($sql); $proteinContent = ''; foreach ($protein as $p) { extract($p); $proteinContent .= <<<EOE <tr> <td>{$title}</td> <td>{$description}</td> <td>{$rating}</td> <td>{$mainIngredient}</td> <td>{$servings}</td> <td>{$pricePerServing}</td> <td>{$percentOff}%</td> <td>{$totalPrice}</td> <td>{$bodyBuildingPrice}</td> </tr> EOE; } $title = "Bob's Burgers"; require_once 'core/top.php';