<?php

require '../core.php';
try {
    $config = array('host' => 'localhost', 'user' => 'root', 'password' => 'adminadmin', 'database' => 'GroceryList', 'fetchMode' => \PDO::FETCH_ASSOC, 'charset' => 'utf8', 'port' => 3306, 'unixSocket' => null);
    // standard setup
    $dbh = new \Simplon\Mysql\Mysql($config['host'], $config['user'], $config['password'], $config['database']);
    $success = $dbh->executeSql("CREATE TABLE Users (\nUserId MEDIUMINT(8) UNSIGNED AUTO_INCREMENT PRIMARY KEY, \nemail VARCHAR(255) NOT NULL\n)");
    if ($success) {
        echo "Table \"Users\" created.";
    }
} catch (Exception $e) {
    $message = json_decode($e->getMessage());
    echo $message->errorInfo->message . "</br>dbFoodInfoTableCreate.php - line 41";
}
<?php

require __DIR__ . '/../vendor/autoload.php';
$config = ['server' => 'localhost', 'username' => 'rootuser', 'password' => 'rootuser', 'database' => 'beatguide_devel_service'];
$dbh = new \Simplon\Mysql\Mysql($config['server'], $config['username'], $config['password'], $config['database']);
// ############################################
echo "<h1>IN with integers</h1>";
$conds = ['ids' => [1, 2, 3, 4, 5]];
$query = 'SELECT id, email FROM users WHERE id IN (:ids)';
var_dump($dbh->fetchRowMany($query, $conds));
// ############################################
echo "<h1>IN with strings</h1>";
$conds = ['emails' => ['*****@*****.**', '*****@*****.**']];
$query = 'SELECT id, email FROM users WHERE email IN (:emails)';
var_dump($dbh->fetchRowMany($query, $conds));
Esempio n. 3
0
<?php

require __DIR__ . '/vendor/autoload.php';
require __DIR__ . '/config/config.php';
$dbConn = new \Simplon\Mysql\Mysql($config['db']['host'], $config['db']['user'], $config['db']['password'], $config['db']['database']);
$result = ['gender' => [], 'age' => [], 'top5_interest' => []];
$gender_distribution = $dbConn->fetchRowMany('SELECT sex, COUNT(*) as count FROM members GROUP BY sex ORDER BY count DESC;');
$gender_id_to_string = [1 => 'female', 2 => 'male', 0 => '?'];
foreach ($gender_distribution as $gender) {
    $result['gender'][$gender_id_to_string[$gender['sex']]] = $gender['count'];
}
$date_format = 'Y-m-d';
$column_name = '`birth_date`';
$age_dates = ['<=10' => "{column} >= '" . date($date_format, strtotime("-10 years", time())) . "'", '11-20' => "{column} >= '" . date($date_format, strtotime("-20 years", time())) . "' AND {column} < '" . date($date_format, strtotime("-10 years", time())) . "'", '21-30' => "{column} >= '" . date($date_format, strtotime("-30 years", time())) . "' AND {column} < '" . date($date_format, strtotime("-20 years", time())) . "'", '>31' => "{column} < '" . date($date_format, strtotime("-30 years", time())) . "'", '?' => "{column} IS NULL"];
$total = 0;
foreach ($age_dates as $name => $condition) {
    $query = str_ireplace('{column}', $column_name, "SELECT COUNT(*) as count FROM `members` WHERE " . $condition);
    $age_distribution = $dbConn->fetchRow($query);
    $result['age'][$name] = $age_distribution['count'];
}
$interests_distribution = $dbConn->fetchRowMany('SELECT interest, COUNT( * ) AS count FROM interests GROUP BY interest ORDER BY count DESC LIMIT 0 , 6');
$interests = [];
foreach ($interests_distribution as $interest) {
    if ($interest['interest'] == 'music') {
        continue;
    }
    $interests[] = $interest['interest'];
}
$result['top5_interest'] = $interests;
print_r(json_encode($result, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
Esempio n. 4
0
<?php

require '../core.php';
try {
    $config = array('host' => 'localhost', 'user' => 'root', 'password' => 'adminadmin', 'database' => 'mysql', 'fetchMode' => \PDO::FETCH_ASSOC, 'charset' => 'utf8', 'port' => 3306, 'unixSocket' => null);
    // standard setup
    $dbh = new \Simplon\Mysql\Mysql($config['host'], $config['user'], $config['password'], $config['database']);
    $success = $dbh->executeSql("CREATE DATABASE GroceryList");
    if ($success) {
        echo "Database \"GroceryList\" created </br>Current existing databases</br>";
        $show = $dbh->getDbh();
        $databases = $show->query("SHOW DATABASES");
        $iterator = new \Simplon\Mysql\MysqlQueryIterator($databases, "fetch", \PDO::FETCH_NUM);
        $iterator->rewind();
        while ($iterator->valid()) {
            $row = $iterator->current();
            echo $row[0] . "</br>";
            $iterator->next();
        }
    }
} catch (Exception $e) {
    $message = json_decode($e->getMessage());
    echo $message->errorInfo->message . "</br>dbCreate.php - line 45";
}
<?php

require __DIR__ . '/../vendor/autoload.php';
$config = ['server' => 'localhost', 'username' => 'rootuser', 'password' => 'rootuser', 'database' => 'beatguide_devel_service'];
$dbh = new \Simplon\Mysql\Mysql($config['server'], $config['username'], $config['password'], $config['database']);
// ############################################
$query = 'SELECT * FROM events WHERE venue_id = :venueId LIMIT 10';
$conds = array('venueId' => 23);
// ############################################
echo '<h3>fetchValue</h3>';
$results = $dbh->fetchColumn($query, $conds);
var_dump($results);
// ############################################
echo '<h3>fetchValueMany</h3>';
$results = $dbh->fetchColumnMany($query, $conds);
echo '<h4>total rows: ' . $dbh->getRowCount() . '</h4>';
var_dump($results);
// ############################################
echo '<h3>fetchValueManyCursor</h3>';
$counter = 0;
foreach ($dbh->fetchColumnManyCursor($query, $conds) as $result) {
    echo '<h4>#' . ++$counter . ' cursor</h4>';
    var_dump($result);
}
// ############################################
echo '<h3>fetch</h3>';
$results = $dbh->fetchRow($query, $conds);
var_dump($results);
// ############################################
echo '<h3>fetchMany</h3>';
$results = $dbh->fetchRowMany($query, $conds);
Esempio n. 6
0
<?php

require '../core.php';
try {
    $config = array('host' => 'localhost', 'user' => 'root', 'password' => 'adminadmin', 'database' => 'GroceryList', 'fetchMode' => \PDO::FETCH_ASSOC, 'charset' => 'utf8', 'port' => 3306, 'unixSocket' => null);
    // standard setup
    $dbh = new \Simplon\Mysql\Mysql($config['host'], $config['user'], $config['password'], $config['database']);
    $success = $dbh->executeSql("CREATE TABLE Food (\nfoodId MEDIUMINT(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY, \ndescription VARCHAR(255) NOT NULL, \nUPC BIGINT(12) NULL, \ncategory VARCHAR(255) NOT NULL, \nnutritionalInfoId MEDIUMINT(12) NOT NULL\n)");
    if ($success) {
        echo "Table \"Food\" created.";
    }
} catch (Exception $e) {
    $message = json_decode($e->getMessage());
    echo $message->errorInfo->message . "</br>dbFoodInfoTableCreate.php - line 41";
}
<?php

require '../core.php';
try {
    $config = array('host' => 'localhost', 'user' => 'root', 'password' => 'adminadmin', 'database' => 'GroceryList', 'fetchMode' => \PDO::FETCH_ASSOC, 'charset' => 'utf8', 'port' => 3306, 'unixSocket' => null);
    // standard setup
    $dbh = new \Simplon\Mysql\Mysql($config['host'], $config['user'], $config['password'], $config['database']);
    $success = $dbh->executeSql("Create Table NutritionalInfo (\nNutrionalinfoid Tinyint(6) Unsigned Auto_Increment Primary Key,\nCalories MEDIUMINT(6) Null,\nCaloriesUnit Char(2) Null,\nProtein MEDIUMINT(6) Null,\nProteinUnit Char(2) Null,\nFat MEDIUMINT(6) Null,\nFatUnit Char(2) Null,\nCarbohydrates MEDIUMINT(6) Null,\nCarbohydratesUnit Char(2) Null,\nSugars MEDIUMINT(6) Null,\nSugarsUnit Char(2) Null,\nFiber MEDIUMINT(6) Null,\nFiberUnit Char(2) Null,\nCalcium MEDIUMINT(6) Null,\nCalciumUnit Char(2) Null,\nIron Decimal(6,2) Null,\nIronUnit Char(2) Null,\nMagnesium MEDIUMINT(6) Null,\nMagnesiumUnit Char(2) Null,\nPotassium MEDIUMINT(6) Null,\nPotassiumUnit Char(2) Null,\nSodium MEDIUMINT(6) Null,\nSodiumUnit Char(2) Null,\nZinc MEDIUMINT(6) Null,\nZincUnit Char(2) Null,\n`Vitamin C` MEDIUMINT(6) Null,\nCUnit Char(2) Null,\nThiamin Decimal(6,4) Null,\nThiaminUnit Char(2) Null,\nRiboflavin Decimal(6,4) Null,\nRiboflavinUnit Char(2) Null,\nNiacin Decimal(6,4) Null,\nNiacinUnit Char(2) Null,\n`Vitamin B-6` Decimal(6,4) Null,\n`B-6Unit` Char(2) Null,\nFolate Decimal(6,4) Null,\nFloateUnit Char(2) Null,\n`Vitamin B-12` Decimal(6,4) Null,\n`B-12Unit` Char(2) Null,\n`Vitamin A` Decimal(6,4) Null,\nAUnit Char(2) Null,\n`Vitamin E` Decimal(6,4) Null,\nEUnit Char(2) Null,\n`Vitamin D` Decimal(6,4) Null,\nDUnit Char(2) Null,\n`Vitamin K` Decimal(6,4) Null,\nKUnit Char(2) Null,\nSaturated Decimal(6,4) Null,\nSaturatedUnit Char(2) Null,\nMonounsaturated Decimal(6,4) Null,\nMonounsaturatedUnit Char(2) Null,\nPolyunsaturated Decimal(6,4) Null,\nPolyunsaturatedUnit Char(2) Null,\nCholesterol Decimal(6,4) Null,\nCholesterolUnit Char(2) Null,\nCaffeine Decimal(6,4) Null,\nCaffeineUnit Char(2) Null\n)");
    if ($success) {
        echo "Table \"NutrionalInfo\" created.";
    }
} catch (Exception $e) {
    $message = json_decode($e->getMessage());
    echo $message->errorInfo->message . "</br>dbNutritionalInfoTableCreate.php - line 93";
}
Esempio n. 8
0
<?php

require __DIR__ . '/vendor/autoload.php';
require __DIR__ . '/config/config.php';
exit;
$vk = new \BW\Vkontakte($config['vk']);
$dbConn = new \Simplon\Mysql\Mysql($config['db']['host'], $config['db']['user'], $config['db']['password'], $config['db']['database']);
require __DIR__ . '/prepare-db.php.php';
// get group info
$group = $vk->api('groups.getById', ['group_id' => $config['group_id'], 'fields' => 'members_count'])[0];
$dbConn->insert('groups', ['vk_id' => $group['id']]);
$request_count = 1000;
$members_count = $group['members_count'];
$iterations_count = $members_count / $request_count;
for ($i = 0; $i < $iterations_count; $i++) {
    echo 'Fetching users ' . $request_count * $i . ' - ' . ($request_count * $i + $request_count) . PHP_EOL;
    $members = $vk->api('groups.getMembers', ['group_id' => $config['group_id'], 'fields' => 'sex,bdate', 'offset' => $request_count * $i, 'count' => $request_count]);
    echo 'Inserting them to database' . PHP_EOL;
    foreach ($members['items'] as $member) {
        $birth_date = null;
        if (isset($member['bdate'])) {
            $bdateParts = explode('.', $member['bdate']);
            $birth_date = count($bdateParts) == 3 ? implode('-', array_reverse($bdateParts)) : null;
        }
        $putMemeber = ['vk_id' => $member['id'], 'sex' => $member['sex'], 'birth_date' => $birth_date];
        try {
            $dbConn->insert('members', $putMemeber);
        } catch (Exception $e) {
        }
    }
}
<?php

require '../core.php';
try {
    $config = array('host' => 'localhost', 'user' => 'root', 'password' => 'adminadmin', 'database' => 'GroceryList', 'fetchMode' => \PDO::FETCH_ASSOC, 'charset' => 'utf8', 'port' => 3306, 'unixSocket' => null);
    // standard setup
    $dbh = new \Simplon\Mysql\Mysql($config['host'], $config['user'], $config['password'], $config['database']);
    $success = $dbh->executeSql("CREATE TABLE GroceryList (\ngroceryListId MEDIUMINT(8) UNSIGNED AUTO_INCREMENT PRIMARY KEY, \nuserId MEDIUMINT(8) NOT NULL,\ngroceryList VARCHAR(10000) NOT NULL\n)");
    if ($success) {
        echo "Table \"GroceryList\" created.";
    }
} catch (Exception $e) {
    $message = json_decode($e->getMessage());
    echo $message->errorInfo->message . "</br>dbFoodInfoTableCreate.php - line 41";
}
Esempio n. 10
0
<?php

require 'core.php';
session_start();
$config = array('host' => 'localhost', 'user' => 'root', 'password' => 'adminadmin', 'database' => 'groceryList', 'fetchMode' => \PDO::FETCH_ASSOC, 'charset' => 'utf8', 'port' => 3306, 'unixSocket' => null);
$dbConn = new \Simplon\Mysql\Mysql($config['host'], $config['user'], $config['password'], $config['database']);
$id = $dbConn->fetchRow("SELECT * FROM users WHERE id = " . $_SESSION["userid"]);
if ($_SESSION['userid'] == $id["id"]) {
    header("Location: groceryList.php");
}
session_unset();
?>
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>Grocery List</title>
        <meta name="viewport" content="width=device-width,initial-scale=1.0">
        <meta name="author" content="@shavez00">
        <link href="css/style.css" rel="stylesheet">
    </head>

    <body>

        <div class="wrapper">
            <div id="main" style="padding:50px 0 0 0;">

                <!-- Form -->
                <form id="contact-form" action="groceryList.php" method="get">
                    <h3>Grocery List</h3></br>
                    <h3>MVP</h3>