示例#1
0
    return mysqli_real_escape_string($msq, $str);
}
// ---------------------------------------------------------
// Unit tests
// ---------------------------------------------------------
if (isset($_SERVER["argv"]) && isset($_SERVER["SCRIPT_FILENAME"]) && basename($_SERVER["SCRIPT_FILENAME"]) == basename(__FILE__)) {
    echo "cog_database: Running self-tests...\n";
    // set up asserts
    assert_options(ASSERT_ACTIVE, 1);
    assert_options(ASSERT_WARNING, 0);
    assert_options(ASSERT_QUIET_EVAL, 0);
    // Set up the callback
    assert_options(ASSERT_CALLBACK, function ($file, $line, $code) {
        echo "Assertion Failed:\n File '{$file}' \n  Line '{$line}'  Code '{$code}'\n\n";
    });
    assert(initsql());
    assert(resolvequery("VALUES (@email, @example)", array("email" => "*****@*****.**", "example" => 123)) == 'VALUES ("*****@*****.**", "123")');
    // table-based testing
    dbcommit("drop table if exists cog_testing");
    dbcommit("create table if not exists cog_testing (id int primary key auto_increment, username varchar(64), status enum('live', 'deleted') default 'live', created datetime )");
    dbinsert("cog_testing", ["username" => random_string(16)], ["created" => "now()"]);
    $q = gettable("select * from cog_testing where status = 'live' ");
    assert(count($q) == 1);
    // unique insert testing
    $res = dbuniqueinsert("cog_testing", ["username" => "unique"], ["username" => "unique", "status" => "live"], ["created" => "now()"]);
    assert($res !== false);
    // this should return with new ID
    $q = gettable("select * from cog_testing where status = 'live' ");
    assert(count($q) == 2);
    $res = dbuniqueinsert("cog_testing", ["username" => "unique"], ["username" => "unique", "status" => "live"], ["created" => "now()"]);
    assert($res == 0);
示例#2
0
文件: guestbook.php 项目: sdrinf/cog
<?php

// cog core modules
include_once "./engine/_config.php";
include_once "./engine/cog_common.php";
include_once "./engine/cog_errorhandler.php";
include_once "./engine/cog_database.php";
include_once "./engine/cog_logger.php";
include_once "./engine/cog_scriptor.php";
include_once "./engine/cog_variants.php";
include_once "./engine/cog_webhandler.php";
include_once "./engine/cog_session.php";
initsql();
// initalize database
session_start();
// start session
log_start();
// log request
variants_start();
// initalizes variants
// create a new webhandler for all requests
$w = new WebHandler(["/" => "site_guestbook/guestbook.php", "/purchase" => "site_guestbook/purchase.php", "/thanks" => "site_guestbook/thanks.html", "/admin" => "site_admin/multivariants.php", "/user_api" => "site_admin/user_api.php", "(.*)" => "site_guestbook/notfound.php"], ["title" => "Cog - guestbook example", "frame" => "site_guestbook/frame.html"]);
// print_r($w); exit;
echo $w->result();