function remainingCourses() { $db = new DatabaseConnector(); $return = []; $stmt = "SELECT CourseInfo.courseID, CourseInfo.courseName, CourseInfo.credits, StudentCourse.weight, StudentCourse.relevance FROM StudentCourse INNER JOIN CourseInfo ON StudentCourse.courseInfoID = CourseInfo.courseInfoID WHERE userID = ? AND (grade = 'IP' OR grade = 'ND')"; $params = array($this->userID); $output = $db->select($stmt, $params); if (count($output) == 0) { $this->log->toLog(2, __METHOD__, "No course information available"); echo json_encode([]); return; } for ($i = 0, $c = count($output); $i < $c; $i++) { if ($output[$i][3] == "") { $this->log->toLog(3, __METHOD__, "weight is null"); } else { if ($output[$i][4] == "") { $this->log->toLog(3, __METHOD__, "relevance is null"); } } $courseID = $output[$i][0]; $courseName = $output[$i][1]; $credits = $output[$i][2]; $courseWeight = $output[$i][3]; $courseRelevance = $output[$i][4]; array_push($return, array($courseID, $courseName, $credits, $courseWeight, $courseRelevance)); } echo json_encode($return); return $return; }
public function getRandomBd() { $dbConnector = new DatabaseConnector(); $dbh = $dbConnector->getDbh(); $sql = "SELECT id, illustrator, scenarist, colorist, cover\n\t\tFROM books\n\t\tORDER BY RAND()\n\t\tLIMIT 20"; $sth = $dbh->prepare($sql); $sth->execute(); $movies = $sth->fetchAll(); return $books; }
/** * Récupère x films au hazard depuis la table movies */ public function getRandomMovies() { $dbConnector = new DatabaseConnector(); $dbh = $dbConnector->getDbh(); $sql = "SELECT id, title, year, imdb_id\n\t\t\t\t\tFROM movies\n\t\t\t\t\tORDER BY RAND()\n\t\t\t\t\tLIMIT 30"; $sth = $dbh->prepare($sql); $sth->execute(); $movies = $sth->fetchAll(); return $movies; }
public function find($id) { $dbConnector = new DatabaseConnector(); $dbh = $dbConnector->getDbh(); $sql = "SELECT *\n\t\t\t\t\tFROM {$this->table}\n\t\t\t\t\tWHERE id = :id"; $sth = $dbh->prepare($sql); $sth->bindValue(":id", $id); $sth->execute(); $row = $sth->fetch(); return $row; }
function getConnection() { global $dbConnection; $dbConnector = new DatabaseConnector(); $dbConnection = $dbConnector->connect(); if ($dbConnection == "Failed to connect") { return json_encode("Connection to the database has failed"); } else { return json_encode("Connection successful"); } }
static function GetDatabase() { if (self::$database == NULL) { self::$database = new medoo(array('database_type' => 'mysql', 'database_name' => 'CompanyCalendar', 'server' => 'localhost', 'username' => 'root', 'password' => 'swe6623', 'charset' => 'utf8')); } return self::$database; }
public function __construct() { $db = new DatabaseConnector(); $res = $db->getPlex($_SESSION['CurrentUserID']); $row = $res->fetch_assoc(); $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, "https://plex.tv/users/sign_in.xml"); curl_setopt($curl, CURLINFO_HEADER_OUT, true); curl_setopt($curl, CURLOPT_HTTPHEADER, array('X-Plex-Platform: ' . PHP_OS, 'X-Plex-Client-Identifier: ' . 1234321423, 'X-Plex-Product: SHMWD')); curl_setopt($curl, CURLOPT_POST, 3); curl_setopt($curl, CURLOPT_USERPWD, "{$row['plexUser']}:{$row['plexPassword']}"); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $result = curl_exec($curl); $headerSent = curl_getinfo($curl, CURLINFO_HEADER_OUT); curl_close($curl); $this->splitted = explode(" ", $result); }
function sendMsg($old, $id, $msg) { $db = new DatabaseConnector(); $newData = $db->GetServerMessages(); if ($old != $newData) { //send a command; print_r($newData); $row = null; foreach ($newData as $n) { $row = $n; } print_r($row); print "<br>"; echo "id: " . $row['messageType'] . PHP_EOL; echo "data: " . $row['message'] . PHP_EOL; echo PHP_EOL; ob_flush(); flush(); } return $newData; }
public static function getPurePDO() { if (is_null(self::$pdo)) { $settings = Environment::databaseSettings(); try { $PDO = new PDO($settings['driver'] . ":host=" . $settings['host'] . ";port=" . $settings['port'] . ";dbname=" . $settings['name'], $settings['username'], $settings['password']); } catch (PDOException $e) { throw new DatabaseException(); } self::$purePDO = $PDO; self::$pdo = new FluentPDO($PDO); } return self::$purePDO; }
/** * @return bool */ public function insertJobs() { $response = $this->getResponse(); $connection = DatabaseConnector::getConnection(); if (!isset($response->jobs) || !$response->jobs) { return false; } foreach ($response->jobs as $job) { $preparedStatement = $connection->prepare($this->insertQuery); $preparedStatement->bindParam(':name', $job->name); $preparedStatement->bindParam(':status', $this->getStatusByColor($job->color)); $preparedStatement->bindParam(':created_at', date('Y-m-d H:i:s')); $preparedStatement->execute(); } return true; }
static function establish_connection($options) { if ($options['adapter']) { $options['adapter'] = strtolower($options['adapter']); $adapter_file_name = ACTIVE_RECORD_BASE_PATH . "/connection_adapters/adapters/{$options['adapter']}_adapter.php"; if (file_exists($adapter_file_name)) { require_once $adapter_file_name; } else { throw new Exception("Couldn't find an appropiate adapter for the database connection."); } // Look for a class named <Adapter>Adapter (i.e. MysqliAdapter) $adapter_class_name = ucfirst($options['adapter']) . 'Adapter'; if (!class_exists($adapter_class_name)) { throw new Exception("Expected {$adapter_file_name} to define class {$adapter_class_name}."); } if (self::$connection = new $adapter_class_name($options)) { return true; } } }
public function getAllCoursesNeeded() { $dbc = new DatabaseConnector(); $params = array($this->userID); $courses = $dbc->select("SELECT DISTINCT CourseInfo.courseID, CourseInfo.credits, StudentCourse.weight,\n StudentCourse.relevance, StudentCourse.studentCourseID FROM StudentCourse INNER JOIN\n CourseInfo ON CourseInfo.courseInfoID = StudentCourse.courseInfoID WHERE StudentCourse.userID = ?\n and grade = 'ND'", $params); $output = array(); foreach ($courses as $course) { $this->log->toLog(0, __METHOD__, "courseID: {$course['0']},\n credits: {$course['1']}, weight: {$course['2']}, relevance: {$course['3']}, id: {$course['4']},"); array_push($output, array('courseID' => $course[0], 'credits' => $course[1], 'weight' => $course[2], 'relevance' => $course[3], 'id' => $course[4])); } echo json_encode($output); }
TrackBack here. Main source of information was: http://www.movabletype.org/docs/mttrackback.html Thanks for this useful piece of information :) MEMO: I don't really like TrackBack... */ error_reporting(E_ERROR | E_PARSE); require_once './config.php'; require_once $CONFIG['LibDir'] . 'common.php'; require_once $CONFIG['LibDir'] . 'db/' . $CONFIG['DatabaseType'] . '.php'; require_once $CONFIG['LibDir'] . 'page/pagerequest.php'; require_once $CONFIG['LibDir'] . 'sys/console.php'; $console = new SystemConsole(); $connector = new DatabaseConnector(); $connector->setupConnection($CONFIG['DatabaseHost'], $CONFIG['DatabaseUser'], $CONFIG['DatabasePassword'], $CONFIG['DatabaseName'], $CONFIG['DatabasePort']); $request = new pageRequest($connector); $request->parseRequest(); if (isset($_POST['url'])) { $ping_url = $_POST['url']; } else { $ping_url = ""; } if ($ping_url == "") { header("Location: index.php?" . $request->getRequestedSite() . "/" . $request->getRequestedPage()); } if (isset($_POST['title'])) { $ping_title = $_POST['title']; } else { $ping_title = "";
} public function getPlex($userID) { $sql = "SELECT * FROM plexservers WHERE userID=" . $userID . ";"; $connection = new mysqli($this->serverName, $this->username, $this->password, "hackusu"); return $connection->query($sql); } } if (isset($_POST['login']) && $_POST['login'] == True) { session_start(); $db = new DatabaseConnector(); $db->LoginUser($_POST['user'], $_POST['passwd']); } if (isset($_POST['plexAdd']) && $_POST['plexAdd'] == True) { session_start(); $db = new DatabaseConnector(); $db->addPlex($_SESSION['CurrentUserID'], $_POST["userID"], $_POST['plexPASSWORD']); $res = $db->getPlex($_SESSION['CurrentUserID']); $row = $res->fetch_assoc(); /*$curl = curl_init(); echo PHP_OS . "<br>"; curl_setopt ($curl, CURLOPT_URL,"https://plex.tv/users/sign_in.xml"); // curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY); curl_setopt($curl, CURLINFO_HEADER_OUT, true); curl_setopt($curl, CURLOPT_HTTPHEADER, array( 'X-Plex-Platform: ' . PHP_OS, 'X-Plex-Client-Identifier: ' . 1234321423, 'X-Plex-Product: SHMWD' )); curl_setopt($curl, CURLOPT_POST, 3); curl_setopt($curl, CURLOPT_USERPWD, "$row[plexUser]:$row[plexPassword]");
<?php session_start(); require_once '../models/database.php'; require_once '../models/lesson.php'; $db = new DatabaseConnector($_SESSION['user_id']); $lesson = $db->getLessonById($_POST['id']); $lesson->setActive($_POST['state'] == "true" ? 1 : 0); $db->updateLesson($lesson); /*$pdo = new PDO("mysql:host=localhost;dbname=vokabeltrainer", "root", "123"); $lesson["id"]=$_POST['id']; $lesson["state"]=($_POST['state']=="true"?1:0); $statement=$pdo->prepare("UPDATE lessons SET active = :state WHERE id = :id"); $statement->execute($lesson);*/ echo "Set lesson with id " . $lesson->getId() . " to " . $lesson->getActive();
public function __construct() { $this->db = DatabaseConnector::getDatabase(); }
</script> <title>Lektionen</title> </head> <body> <table class='manage' id='lesson_table'> <caption>Lektionen verwalten</caption> <thead> <tr> <th><input type="checkbox" id="check_all"></th> <th>Name</th> <th>Vokabeln</th> <th></th> </tr> </thead> <?php $db = new DatabaseConnector($_SESSION['user_id']); $lesson_list = $db->getAllLessons(); foreach ($lesson_list as $lesson) { if ($lesson->getName() == "Unsortiert") { echo "<tr><td></td><td><a href='manage_vocables.inc.php?name=" . $lesson->getName() . "'>" . $lesson->getName() . "</a></td><td>" . $db->countLessonVocs($lesson->getId()) . "</td><td></tr>"; } else { echo "<tr><td><input type='checkbox' value='" . $lesson->getName() . "' id='l-" . $lesson->getName() . "'/></td><td><a href='manage_vocables.inc.php?name=" . $lesson->getName() . "'>" . $lesson->getName() . "</a></td><td>" . $db->countLessonVocs($lesson->getId()) . "</td><td><button onclick='change(this)' value='" . $lesson->getName() . "'>Umbenennen</button></td></tr>"; } } ?> </table> <div class='bottom_line'> <form action='new_lesson.inc.php' method="post" style='display:inline;'> <input type='submit' id='new' value='Neue Lektion/Import'> <input type='hidden' name='origin' value='manage_lessons.php'> </form>
<!DOCTYPE html> <html> <head> <title>DB test</title> </head> <body> <?php require_once 'connector.php'; ?> <?php DatabaseConnector::$host = "localhost"; DatabaseConnector::$username = "******"; DatabaseConnector::$password = "******"; DatabaseConnector::$dbname = "myDatabase"; $conn = new DatabaseConnector(); $rs = $conn->Query("SELECT * FROM `users`;"); while ($result = mysqli_fetch_assoc($rs)) { var_dump($rs); } var_dump($conn->affected_rows()); var_dump($conn->ConnectError()); var_dump($conn->ConnectErrorNo()); /** * And more tests */ ?> </body> </html>
<?php header("Access-Control-Allow-Origin: *"); header("Content-Type: application/json; charset=UTF-8"); include 'connectDatabase.php'; $connection = new DatabaseConnector(); $con = $connection->connect(); $response = array(); if ($con) { // Selecting database $database = mysql_select_db("leaf_me_alone"); if ($database) { $select_query = "select * from leafs"; $result = mysql_query($select_query) or die(mysql_error()); if (!empty($result)) { if (mysql_num_rows($result) > 0) { $response["leafs"] = array(); while ($row = mysql_fetch_array($result)) { $leaf = array(); $leaf["id"] = $row["id"]; $leaf["location"] = $row["location"]; $leaf["defect_percentage"] = $row["defect_percentage"]; $leaf["time_stamp"] = $row["time_stamp"]; $leaf["salt_name"] = $row["salt_name"]; array_push($response["leafs"], $leaf); } $response["success"] = 1; echo json_encode($response); } else { $response["success"] = 0; $response["message"] = "No found";
<?php session_start(); require_once '../models/database.php'; require_once '../models/vocable.php'; require_once '../models/lesson.php'; $ids = json_decode($_POST['ids']); $db = new DatabaseConnector($_SESSION['user_id']); foreach ($ids as $id) { //ID and user_id are safe enough //$voc=$db->getVocById($id); $db->deleteVocById($id); } echo "Done";
function modifyWeightAndRelevance() { $db = new DatabaseConnector(); if (isset($_POST['courseID'])) { $courseID = $_POST['courseID']; } else { $courseID = ""; } if (isset($_POST['modifiedRelevance'])) { $modifiedRelevance = $_POST['modifiedRelevance']; } else { $modifiedRelevance = ""; } if (isset($_POST['modifiedWeight'])) { $modifiedWeight = $_POST['modifiedWeight']; } else { $modifiedWeight = ""; } $stmt = "UPDATE StudentCourse SET relevance = ?, weight = ? WHERE courseInfoID = (SELECT courseInfoID FROM CourseInfo WHERE courseID = ?) AND userID = ?"; $params = array($modifiedRelevance, $modifiedWeight, $courseID, $this->userID); $db->query($stmt, $params); $this->log->toLog(1, __METHOD__, "weight and relevance have been modified"); }
function __construct() { $this->database = DatabaseConnector::GetDatabase(); }
/** * Create new model instance. */ public function __construct() { parent::__construct(); }
<?php session_start(); require_once 'models/database.php'; require_once 'models/user.php'; if (isset($_GET['login'])) { $email = $_POST['email']; $password = $_POST['password']; $db = new DatabaseConnector(); $user = $db->getUserByEmail($email); //Überprüfung des Passworts if ($user !== false && $user->verifyPassword($password)) { $_SESSION['user_id'] = $user->getId(); $_SESSION['email'] = $email; //TODO: Use Session variable to redirect to the page the user was trying to access if (isset($_SESSION['origin_url'])) { echo "<script>top.window.location='" . $_SESSION['origin_url'] . "';</script>"; //header("Location: ".$_SESSION['origin_url']); } else { echo "<script>top.window.location='index.php';</script>"; //header("Location: index.php"); } die; } else { $errorMessage = "E-Mail oder Passwort war ungültig<br>"; } } ?> <html> <head> <link rel="stylesheet" href="style/main.css" type="text/css">
<?php session_start(); require_once '../models/database.php'; $db = new DatabaseConnector($_SESSION['user_id']); $plan = $_POST['plan'] == "true" ? true : false; $steps = json_decode($_POST['steps']); $direction = $_POST['direction']; //Store options to database $options = ["plan" => $plan, "direction" => $direction, "steps" => $steps]; $db->saveOptions($options); $_SESSION['count'] = $db->prepareLearnVocables($plan, $steps); $_SESSION['direction'] = $direction; $_SESSION['plan'] = $plan; //Reset result counts $_SESSION['right_c'] = 0; $_SESSION['wrong_c'] = 0; $_SESSION['mastered_c'] = 0; $db->setResultCount("right_c", 0); $db->setResultCount("wrong_c", 0); $db->setResultCount("mastered_c", 0);
function test005() { $sc = new SettingsController(12, 'newuser20'); $sc->importReq('nursing.xml'); $db = new DatabaseConnector(); $params = array(5); $buckets = $db->select("Select description from MajorBucket Where majorID = ?", $params); $output = array(); $b = array(); foreach ($buckets as $bucket) { array_push($b, $bucket[0]); } array_push($output, $b); $courses = $db->select("SELECT CourseInfo.courseID FROM CourseInfo\n INNER JOIN MajorBucketRequiredCourses ON MajorBucketRequiredCourses.courseInfoID = CourseInfo.courseInfoID\n WHERE MajorBucketRequiredCourses.bucketID IN (SELECT bucketID FROM MajorBucket WHERE majorID = ?)", $params); $c = array(); foreach ($courses as $course) { array_push($c, $course[0]); } array_push($output, $c); $expected = [["Chemistry & Lab", "Human Anatomy & Lab", "Human Growth & Development", "Human Physiology & Lab", "Intro to Ethics", "Intro to Psychology", "Junior 1: Semester 1", "Junior 2: Semester 2", "Junior 2: Semester 3", "Microbiology & Lab", "Nursing Core", "Nutrition", "Prerequisites", "Senior 3: Semester 1", "Senior 4: Semester 2", "Statistics"], ["ZOO3731", "ZOO3731L", "PCB2099", "PCB2099L", "MCB2000", "MCB2000L", "CHM1045L", "CHM1045", "STA2023", "HUN2201", "DEP2000", "PSY2012", "PHI2600", "NUR3029", "NUR3029C", "NUR3029L", "NUR3125", "NUR3066C", "NUR3226", "NUR3226L", "NUR3145", "NUR3666", "NSP3801", "NUR3821", "NUR3227", "NUR3227L", "NUR4455", "NUR4455L", "NUR3685L", "NUR3535", "NUR3535L", "NUR4355", "NUR4355L", "NUR4686L", "NUR4667", "NUR4636C", "NUR4286", "NUR4940", "NUR4945L"]]; $this->assertEquals($output, $expected); }
<?php include 'connect.php'; $dc = new DatabaseConnector(); $con = $dc->getConnection(); include 'functions.php'; $action = $_GET['action']; $user = $_GET['user']; $my_id = $_SESSION['user_id']; if ($action == 'send') { mysqli_query($con, "INSERT INTO frnd_req VALUES('', '{$my_id}', '{$user}')"); } if ($action == 'accept') { mysqli_query($con, "DELETE FROM `frnd_req` WHERE `from`='{$user}' AND `to`='{$my_id}'"); mysqli_query($con, "INSERT INTO friends VALUES ('','{$user}', '{$my_id})"); } if ($action == 'unfrnd') { mysqli_query($con, "DELETE FROM friends WHERE(user_id='{$my_id}' AND friend_id='{$user}') OR (user_id='{$user}' AND friend_id='{$my_id}')"); } header('Location: profile,php?user=' . $user);
<?php session_start(); require_once '../models/database.php'; require_once '../models/vocable.php'; $date = date("Y-m-d"); $db = new DatabaseConnector($_SESSION['user_id']); //if request come from change-site, update the vocable and return to managing page if (isset($_POST['change'])) { $voc = $db->getVocById($_POST['id']); $voc->setOwnLang($_POST['ownLanguage']); $voc->setForeignLang($_POST['foreignLanguage']); $db->updateVoc($voc); header("Location: " . $_POST['origin']); die; } $voc = new Vocable($_SESSION['user_id'], $_POST["ownLanguage"], $_POST["foreignLanguage"], $_POST["lesson"], $date); $db->createVoc($voc); /*$pdo = new PDO("mysql:host=localhost;dbname=vokabeltrainer", "root", "123"); #Prepare Array for insert $newVocable["ol"]=$_POST["ownLanguage"]; $newVocable["fl"]=$_POST["foreignLanguage"]; $newVocable["lesson"]=$_POST["lesson"]; $newVocable["nextDate"]=$_POST["date"]; $newVocable["user_id"]=$_SESSION['user_id']; $statement = $pdo->prepare("INSERT INTO vocables (own_language, foreign_language, lesson, next_date, user_id) VALUES (:ol, :fl, :lesson, :nextDate, :user_id)"); $statement->execute($newVocable); $id=$pdo->lastInsertId();*/ echo TRUE;
/** * Returns the maximum image id (id of the last image) */ public function getMaxImageId() { return DatabaseConnector::getPurePDO()->query("SELECT MAX(photo_id) FROM animal")->fetch()[0]; }
function getGrades($assessment, $course) { $db = new DatabaseConnector(); $return = []; $stmt = "SELECT grade FROM Assessment WHERE assessmentTypeID in (select assessmentTypeID FROM AssessmentType WHERE AssessmentName = ?) AND studentCourseID in (SELECT studentCourseID FROM StudentCourse WHERE grade = 'IP' and userID = ? AND courseInfoID in (select courseInfoID FROM CourseInfo WHERE courseID = ?))"; $params = array($assessment, $this->userID, $course); $output = $db->select($stmt, $params); if (count($output) == 0) { $this->log->toLog(2, __METHOD__, "No grades returned form assessment"); echo json_encode([]); return $return; } $index = 1; for ($i = 0, $c = count($output); $i < $c; $i++) { $grades = $output[$i][0]; $this->log->toLog(0, __METHOD__, "Grade: {$grades}"); array_push($return, array("Grade" . $index, $grades)); $index++; } echo json_encode($return); return $return; }