Exemple #1
0
 /**
  *
  * @param type $force
  * @return type
  */
 public function getMySqlDB($force = false)
 {
     if (is_null($this->mySqlDB) || $force) {
         $username = \Config::$MYSQL_USERNAME;
         $password = \Config::$MYSQL_PASSWORD;
         $database = \Config::$MYSQL_DATABASE;
         if (isset($GLOBALS['__PHPUNIT_BOOTSTRAP'])) {
             $username = \Config::$MYSQL_USERNAME_TEST;
             $password = \Config::$MYSQL_PASSWORD_TEST;
             $database = \Config::$MYSQL_DATABASE_TEST;
         }
         $this->mySqlDB = new Database(\Config::$MYSQL_HOST, $username, $password, $database, \Config::$DEBUG);
         if (!$this->mySqlDB) {
             throw new Exception('Can not connect to Mysql mySqlDB using mysqli driver.');
         }
     }
     if (\Config::$DEBUG) {
         // TEMP HACK:
         $q = 'SET foreign_key_checks = 0;';
         $this->mySqlDB->q($q);
     }
     return $this->mySqlDB;
 }
<?php

error_reporting(E_ALL | E_STRICT);
require_once "../MysqliDb.php";
require_once "../dbObject.php";
$db = new Mysqlidb('localhost', 'root', '', 'testdb');
dbObject::autoload("models");
$tables = array('users' => array('login' => 'char(10) not null', 'active' => 'bool default 0', 'customerId' => 'int(10) not null', 'firstName' => 'char(10) not null', 'lastName' => 'char(10)', 'password' => 'text not null', 'createdAt' => 'datetime', 'updatedAt' => 'datetime', 'expires' => 'datetime', 'loginCount' => 'int(10) default 0'), 'products' => array('customerId' => 'int(10) not null', 'userId' => 'int(10) not null', 'productName' => 'char(50)'));
$data = array('user' => array(array('login' => 'user1', 'customerId' => 10, 'firstName' => 'John', 'lastName' => 'Doe', 'password' => $db->func('SHA1(?)', array("secretpassword+salt")), 'expires' => $db->now('+1Y'), 'loginCount' => $db->inc()), array('login' => 'user2', 'customerId' => 10, 'firstName' => 'Mike', 'lastName' => NULL, 'password' => $db->func('SHA1(?)', array("secretpassword2+salt")), 'expires' => $db->now('+1Y'), 'loginCount' => $db->inc(2)), array('login' => 'user3', 'active' => true, 'customerId' => 11, 'firstName' => 'Pete', 'lastName' => 'D', 'password' => $db->func('SHA1(?)', array("secretpassword2+salt")), 'expires' => $db->now('+1Y'), 'loginCount' => $db->inc(3))), 'product' => array(array('customerId' => 1, 'userId' => 1, 'productName' => 'product1'), array('customerId' => 1, 'userId' => 1, 'productName' => 'product2'), array('customerId' => 1, 'userId' => 1, 'productName' => 'product3'), array('customerId' => 1, 'userId' => 2, 'productName' => 'product4'), array('customerId' => 1, 'userId' => 2, 'productName' => 'product5')));
function createTable($name, $data)
{
    global $db;
    //$q = "CREATE TABLE $name (id INT(9) UNSIGNED PRIMARY KEY NOT NULL";
    $q = "CREATE TABLE {$name} (id INT(9) UNSIGNED PRIMARY KEY AUTO_INCREMENT";
    foreach ($data as $k => $v) {
        $q .= ", {$k} {$v}";
    }
    $q .= ")";
    $db->rawQuery($q);
}
// rawQuery test
foreach ($tables as $name => $fields) {
    $db->rawQuery("DROP TABLE " . $name);
    createTable($name, $fields);
}
foreach ($data as $name => $datas) {
    foreach ($data[$name] as $userData) {
        $obj = new $name($userData);
        $id = $obj->save();
        if ($obj->errors) {
            echo "errors:";
Exemple #3
0
<?php

require_once "../MysqliDb.php";
error_reporting(E_ALL);
$prefix = 't_';
$db = new Mysqlidb('localhost', 'root', '', 'testdb');
if (!$db) {
    die("Database error");
}
$mysqli = new mysqli('localhost', 'root', '', 'testdb');
$db = new Mysqlidb($mysqli);
$db = new Mysqlidb(array('host' => 'localhost', 'username' => 'root', 'password' => '', 'db' => 'testdb', 'prefix' => $prefix, 'charset' => null));
if (!$db) {
    die("Database error");
}
$db->setTrace(true);
$tables = array('users' => array('login' => 'char(10) not null', 'active' => 'bool default 0', 'customerId' => 'int(10) not null', 'firstName' => 'char(10) not null', 'lastName' => 'char(10)', 'password' => 'text not null', 'createdAt' => 'datetime', 'updatedAt' => 'datetime', 'expires' => 'datetime', 'loginCount' => 'int(10) default 0', 'unique key' => 'login (login)'), 'products' => array('customerId' => 'int(10) not null', 'userId' => 'int(10) not null', 'productName' => 'char(50)'));
$data = array('users' => array(array('login' => 'user1', 'customerId' => 10, 'firstName' => 'John', 'lastName' => 'Doe', 'password' => $db->func('SHA1(?)', array("secretpassword+salt")), 'createdAt' => $db->now(), 'updatedAt' => $db->now(), 'expires' => $db->now('+1Y'), 'loginCount' => $db->inc()), array('login' => 'user2', 'customerId' => 10, 'firstName' => 'Mike', 'lastName' => NULL, 'password' => $db->func('SHA1(?)', array("secretpassword2+salt")), 'createdAt' => $db->now(), 'updatedAt' => $db->now(), 'expires' => $db->now('+1Y'), 'loginCount' => $db->inc(2)), array('login' => 'user3', 'active' => true, 'customerId' => 11, 'firstName' => 'Pete', 'lastName' => 'D', 'password' => $db->func('SHA1(?)', array("secretpassword2+salt")), 'createdAt' => $db->now(), 'updatedAt' => $db->now(), 'expires' => $db->now('+1Y'), 'loginCount' => $db->inc(3))), 'products' => array(array('customerId' => 1, 'userId' => 1, 'productName' => 'product1'), array('customerId' => 1, 'userId' => 1, 'productName' => 'product2'), array('customerId' => 1, 'userId' => 1, 'productName' => 'product3'), array('customerId' => 1, 'userId' => 2, 'productName' => 'product4'), array('customerId' => 1, 'userId' => 2, 'productName' => 'product5')));
function createTable($name, $data)
{
    global $db;
    //$q = "CREATE TABLE $name (id INT(9) UNSIGNED PRIMARY KEY NOT NULL";
    $db->rawQuery("DROP TABLE IF EXISTS {$name}");
    $q = "CREATE TABLE {$name} (id INT(9) UNSIGNED PRIMARY KEY AUTO_INCREMENT";
    foreach ($data as $k => $v) {
        $q .= ", {$k} {$v}";
    }
    $q .= ")";
    $db->rawQuery($q);
}
// rawQuery test
Exemple #4
0
<?
error_reporting (E_ALL|E_STRICT);
require_once ("../MysqliDb.php");
require_once ("../dbObject.php");

$db = new Mysqlidb('localhost', 'root', '', 'testdb');
$prefix = 't_';
$db->setPrefix($prefix);
dbObject::autoload ("models");

$tables = Array (
    'users' => Array (
        'login' => 'char(10) not null',
        'active' => 'bool default 0',
        'customerId' => 'int(10) not null',
        'firstName' => 'char(10) not null',
        'lastName' => 'char(10)',
        'password' => 'text not null',
        'createdAt' => 'datetime',
        'updatedAt' => 'datetime',
        'expires' => 'datetime',
        'loginCount' => 'int(10) default 0'
    ),
    'products' => Array (
        'customerId' => 'int(10) not null',
        'userId' => 'int(10) not null',
        'productName' => 'char(50)'
    )
);

$data = Array (
<?php

require_once "MysqliDb.php";
error_reporting(E_ALL);
$db = new Mysqlidb('localhost', 'root', '', 'testdb');
if (!$db) {
    die("Database error");
}
$prefix = 't_';
$db->setPrefix($prefix);
$tables = array('users' => array('login' => 'char(10) not null', 'active' => 'bool default 0', 'customerId' => 'int(10) not null', 'firstName' => 'char(10) not null', 'lastName' => 'char(10)', 'password' => 'text not null', 'createdAt' => 'datetime', 'expires' => 'datetime', 'loginCount' => 'int(10) default 0'), 'products' => array('customerId' => 'int(10) not null', 'userId' => 'int(10) not null', 'productName' => 'char(50)'));
$data = array('users' => array(array('login' => 'user1', 'customerId' => 10, 'firstName' => 'John', 'lastName' => 'Doe', 'password' => $db->func('SHA1(?)', array("secretpassword+salt")), 'createdAt' => $db->now(), 'expires' => $db->now('+1Y'), 'loginCount' => $db->inc()), array('login' => 'user2', 'customerId' => 10, 'firstName' => 'Mike', 'lastName' => NULL, 'password' => $db->func('SHA1(?)', array("secretpassword2+salt")), 'createdAt' => $db->now(), 'expires' => $db->now('+1Y'), 'loginCount' => $db->inc(2)), array('login' => 'user3', 'active' => true, 'customerId' => 11, 'firstName' => 'Pete', 'lastName' => 'D', 'password' => $db->func('SHA1(?)', array("secretpassword2+salt")), 'createdAt' => $db->now(), 'expires' => $db->now('+1Y'), 'loginCount' => $db->inc(3))), 'products' => array(array('customerId' => 1, 'userId' => 1, 'productName' => 'product1'), array('customerId' => 1, 'userId' => 1, 'productName' => 'product2'), array('customerId' => 1, 'userId' => 1, 'productName' => 'product3'), array('customerId' => 1, 'userId' => 2, 'productName' => 'product4'), array('customerId' => 1, 'userId' => 2, 'productName' => 'product5')));
function createTable($name, $data)
{
    global $db;
    //$q = "CREATE TABLE $name (id INT(9) UNSIGNED PRIMARY KEY NOT NULL";
    $q = "CREATE TABLE {$name} (id INT(9) UNSIGNED PRIMARY KEY AUTO_INCREMENT";
    foreach ($data as $k => $v) {
        $q .= ", {$k} {$v}";
    }
    $q .= ")";
    $db->rawQuery($q);
}
foreach ($tables as $name => $fields) {
    $db->rawQuery("DROP TABLE " . $prefix . $name);
    createTable($prefix . $name, $fields);
}
foreach ($data as $name => $datas) {
    foreach ($datas as $d) {
        $id = $db->insert($name, $d);
        if ($id) {
Exemple #6
0
 */
ini_set('display_startup_errors', 1);
ini_set('display_errors', 1);
error_reporting(-1);
header('Access-Control-Allow-Origin: *');
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");
header('Content-Type: application/json; charset=utf-8');
//header('Content-Type: text/html; charset=utf-8');
//
require_once './libs/mysqli/MysqliDb.php';
require_once 'libs/Slim/Slim.php';
\Slim\Slim::registerAutoloader();
$app = new \Slim\Slim();
$app->response->headers->set('Content-Type', 'application/json');
$app->response->headers->set('charset', 'utf-8');
$db = new Mysqlidb('db.utfapp.com', 'htv', '123qweasd', 'htv');
if (!$db) {
    die("Database error");
}
require_once './functions/functions.php';
require_once './classes/Log.php';
$log = Log::getInstance();
require_once './classes/DataManager.php';
$app->get('/', function () use($app, $db, $log) {
    $app->response->headers->set('Content-Type', 'text/html');
    echo "HTV!";
});
$app->get('/searchByLocation', function () use($app, $db, $log) {
    if ($app->request()->params('radius') == null) {
        $rad = 10;
    } else {
Exemple #7
0
<?php

require_once '../libs/mysqli/MysqliDb.php';
require_once '../libs/Curl.php';
require_once '../classes/Log.php';
require_once '../classes/DataManager.php';
$db = new Mysqlidb('db.utfapp.com', 'htv', '123qweasd', 'htv');
if (!$db) {
    die("Database error");
}
use Curl\Curl;
$curl = new Curl();
require_once __DIR__ . '/../lib/Dropbox/strict.php';
$appInfoFile = __DIR__ . "/web-file-browser.app";
// NOTE: You should be using Composer's global autoloader.  But just so these examples
// work for people who don't have Composer, we'll use the library's "autoload.php".
require_once __DIR__ . '/../lib/Dropbox/autoload.php';
use Dropbox as dbx;
$requestPath = init();
session_start();
if ($requestPath === "/") {
    $user = $db->getOne('user');
    $dbxClient = new dbx\Client($user['session'], "PHP-Example/1.0");
    //$dbxClient = getClient();
    if ($dbxClient === false) {
        header("Location: " . getPath("dropbox-auth-start"));
        exit;
    }
    $path = "/Pictures";
    if (isset($_GET['path'])) {
        $path = $_GET['path'];