コード例 #1
0
ファイル: index.php プロジェクト: neas5791/dbPart
function addPart($pdo, $descr, $ext)
{
    // function addPart($pdo, $descr, $typeid, $ext){
    // $pdo = dbConnect();
    // echo '<br><span>Hit function addPart().</span><br>';
    try {
        $sql = 'SELECT MAX(id) AS "NEXT_ID" FROM tbPart FOR UPDATE';
        $stmt = $pdo->query($sql);
        $row = $stmt->fetch();
        $next_id = $row['NEXT_ID'] + 1;
    } catch (PDOException $e) {
        $error = 'Failed to count parts' . $e->getMessage();
        echo $error;
    }
    // echo $next_id;
    try {
        // $sql = 'INSERT INTO tbPart (descr, typeid, image) VALUES ( :descr, :typeid, :image )';
        $sql = 'INSERT INTO tbPart (descr, image) VALUES ( :descr, :image )';
        $s = $pdo->prepare($sql);
        $s->bindValue(':descr', $descr, PDO::PARAM_STR);
        // $s -> bindValue(':typeid', $typeid, PDO::PARAM_INT);
        // $filename = ($pdo -> lastInsertId()).$ext;
        $filename = $next_id . $ext;
        $s->bindValue(':image', $filename, PDO::PARAM_STR);
        $s->execute();
        $last_id = $pdo->lastInsertId();
        append_log('#' . $last_id . ' added to part number table');
    } catch (PDOException $e) {
        $error = 'Insert part failed with following error:<br>' . $e->getMessage();
        echo $error;
    }
    return $last_id;
}
コード例 #2
0
ファイル: post-commit.php プロジェクト: michaelprem/phc
$sections = array("author", "changed", "diff", "log");
foreach ($sections as $section) {
    ${$section} = trim(`{$svnlook} {$section} {$repos}`);
}
if ($author == "") {
    $author = "[unknown author]";
}
$body = <<<END
{$log}

# Changed
{$changed}

# Diff
{$diff}
END;
$subject = "svn commit by {$author} (rev {$rev})";
$success = mail("*****@*****.**", $subject, $body, "From: svn@phpcompiler.org\r\n");
// Log the commit
if ($success) {
    append_log("mail delivery ok");
} else {
    append_log("mail delivery failed");
}
function append_log($string)
{
    $file = fopen("/misc/svn/post-commit.log", "a");
    fwrite($file, date("D M j G:i:s Y"));
    fwrite($file, ": {$string}\n");
    fclose($file);
}
コード例 #3
0
ファイル: connect.php プロジェクト: neas5791/dbPart
<?php

// include_once './php/db_const.php';
include_once './include/php/log.php';
const DB_HOST = 'mysql:host=localhost;';
const DB_USER = '******';
const DB_PASS = '******';
const DB_NAME = 'dbname=dbPart';
try {
    $pdo = new PDO(DB_HOST . DB_NAME, DB_USER, DB_PASS);
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $pdo->exec('SET NAMES "utf8"');
} catch (PDOException $e) {
    $error = 'Unable to connect to the database server.<br>' . $e->getMessage();
    echo $error;
}
echo 'database connected';
append_log('Database connection successful');
コード例 #4
0
ファイル: part.php プロジェクト: neas5791/dbPart
<?php

include './include/php/connect.php';
include_once './include/php/log.php';
echo '<script type="text/javascript">console.log("' . $_POST['action'] . ';"</script> -->';
// Insert new part
if (!isset($_POST['action'])) {
    try {
        $sql = 'INSERT INTO tbPart (descr, image) VALUES ( :descr, :image )';
        $s = $pdo->prepare($sql);
        $s->bindValue(':descr', $_POST['descr'], PDO::PARAM_STR);
        // $s -> bindValue(':typeid', $typeid, PDO::PARAM_INT);
        // $filename = './img/'.($pdo -> lastInsertId()).'.jpg';
        $s->bindValue(':image', $_POST['image'], PDO::PARAM_STR);
        $s->execute();
        $last_id = $pdo->lastInsertId();
        append_log('#' . $last_id . ' added to part number table');
    } catch (PDOException $e) {
        $error = 'Insert part failed with following error:<br>' . $e->getMessage();
        echo $error;
    }
}
コード例 #5
0
ファイル: access.inc.php プロジェクト: neas5791/dbPart2
                if ($res[0] == 1) {
                    $_SESSION['id'] = session_id();
                    // Initialize $_SESSION variable
                    $sql = 'SELECT fname FROM tbUser
                  WHERE username = :username
                  AND password = MD5(CONCAT(:password,"mickey mouse"))';
                    $s = $pdo->prepare($sql);
                    $s->bindParam(':password', $password, PDO::PARAM_STR);
                    $s->bindParam(':username', $username);
                    $s->execute();
                    $row = $s->fetch(PDO::FETCH_BOTH);
                    // fetch the first row of results (there should be only one)
                    $_SESSION['username'] = $username;
                    // Initialize $_SESSION variable
                    $_SESSION['name'] = $row['fname'];
                    append_log($username . ' logged in successfully');
                    echo json_encode(array('action' => 'login', 'authorized' => true, 'message' => 'login successful', 'session' => $_SESSION['id'], 'name' => $_SESSION['name']));
                } else {
                    $login_error = "Username or Password is invalid";
                    header('Content-Type: application/json');
                    echo json_encode(array('action' => 'login', 'authorized' => false, 'message' => $login_error));
                }
            } catch (PDOException $e) {
                header('Content-Type: application/json');
                echo json_encode(array('action' => 'login', 'authorized' => false, 'message' => $e->getMessage()));
            }
        }
    }
}
/*
 * action = logout