/** * This method will execute sql query. * * @param queryId - The query id to execute. if no value is given the method will seach for it as request param. * @param params - List of parameters to bind to teh stored procedure. * If no parameters are passed all the request params will be used as bind parameters. * * @return - Returns an array containing all of the result set rows */ public function executeQuery($queryId = null, $params = null) { if (!isset($queryId)) { $queryId = Utils::getParam('queryId', null); if (!isset($queryId)) { throw new Exception('Missing queryId'); } } // ----------------------------------------------------------------------------------- // -- If no parameters are passed auto build the params from all the GET/POST pairs -- // ----------------------------------------------------------------------------------- if (!isset($params)) { $params = array(); // We read the parameters form the request since it contains both get and post params foreach ($_REQUEST as $key => $value) { $params[':' . $key] = $value; } } // Get the query we wish to execute $query = $this->sql_queries[$queryId]; $statment = $this->pdo->prepare($query); $statment->setFetchMode(PDO::FETCH_ASSOC); $statment->execute($params); // Check to see if we have error or not $error = $statment->errorInfo(); // Set the error message if ($error[0] > 0) { $_REQUEST['DBLayer.executeQuery.error'] = $statment->errorInfo(); } // return all the rows return $statment->fetchAll(); }
public function setAllMsgDeleteInThread($threadId) { $sql = $this->getQuery('UPDATE ' . self::$SCHEMA . '.MSG_BOX set "Status"=( CASE WHEN ( "To_User_ID" = ' . $this->userId . ' AND "Status" = ' . self::$DELETED_BY_FROM_USER . ') THEN ' . self::$DELETED_BY_BOTH . ' WHEN ( "From_User_ID" = ' . $this->userId . ' AND "Status" = ' . self::$DELETED_BY_TO_USER . ') THEN ' . self::$DELETED_BY_BOTH . ' WHEN "From_User_ID" = ' . $this->userId . ' AND "Status" = ' . self::$NOT_READED . ' THEN ' . self::$DELETED_FROM_USER_NOT_READED_BY_TO_USER . ' WHEN "To_User_ID" = ' . $this->userId . ' THEN ' . self::$DELETED_BY_TO_USER . ' WHEN "From_User_ID" = ' . $this->userId . ' THEN ' . self::$DELETED_BY_FROM_USER . ' END ) WHERE "MSG_ID" in (Select "ID" from ' . self::$SCHEMA . '.MSG where "Thread_ID"=?) AND ("To_User_ID"=' . $this->userId . ' OR "From_User_ID"=' . $this->userId . ')'); $stmt = $this->pdo->prepare($sql); $stmt->execute(array($threadId)); }
public function displayMsgUser(pdo $conexao, $idUsuario) { try { $msg = ""; $stmtSel = $conexao->prepare(mensagemDAO::$SELECT_MENSAGEM_USER); $stmtSel->execute(array(':idUsuario' => $idUsuario)); $resultado = $stmtSel->fetchAll(); foreach ($resultado as $linha) { $msg .= "<div class='listMsg'>\n <span class='usuario1'>{$linha['3']}</span>"; } return $msg; } catch (PDOException $e) { print_r($e); } }
public function updateInformation($table, $update, $where, $val) { foreach ($update as $key => $value) { $x++; $set .= "" . $key . " = " . $value . ""; if (count($update) > $x) { $set .= ", "; } } try { $db = new pdo($this->db_config["host"], $this->db_config["user"], $this->db_config["pswd"]); $sql = $db->prepare("UPDATE " . $table . " SET " . $set . " WHERE " . $where . " = " . $val . ""); $sql->execute(); unset($db); return $row; } catch (PDOException $e) { die("Database Error: " . $e); return false; } }
if (isset($_SERVER['SERVER_SOFTWARE']) && strpos($_SERVER['SERVER_SOFTWARE'], 'Google App Engine') !== false) { // Connect from App Engine. try { $conn = new pdo('mysql:unix_socket=/cloudsql/artgallery-1156:art;dbname=artgallery', 'root', ''); } catch (PDOException $ex) { die(json_encode(array('outcome' => false, 'message' => 'Unable to connect :(((('))); } } else { // Connect from a development environment. try { $conn = new pdo('mysql:host=173.194.105.221;dbname=artgallery', 'joseph', 'admin'); } catch (PDOException $ex) { die(json_encode(array('outcome' => false, 'message' => 'Unable to connect'))); } } $statement = $conn->prepare("select * from purchases natural join customers where purchases.custname=customers.name and purchaseid= :id"); $statement->bindParam(':id', $id); $statement->execute(); $pur = $statement->fetch(); $pieceid = $pur[pieceid]; $statement = $conn->prepare("select * from art_data natural join art_pieces where pieceid= :id"); $statement->bindParam(':id', $pieceid); $statement->execute(); $gen = $statement->fetch(); echo "<h2>" . $gen[name] . "</h2>"; echo "<table style='width:50%'>"; echo "<tr><td><h4>General Info</h4></td></tr>"; echo "<tr><td>Artist</td><td>" . $gen[artist] . "</td></tr>"; echo "<tr><td>Date</td><td>" . $gen[date] . "</td></tr>"; echo "<tr><td>Price</td><td>\$" . $gen[price] . "</td></tr>"; echo "<tr><td><h4></h4></td></tr>";
<?php echo "this is a database test."; $ip = '192.168.33.61'; $port = '3306'; $user = '******'; $pass = ''; $info = sprintf("mysql:host=%s;port=%s,database=;", $ip, $port); $db = new pdo($info, $user, $pass, array(PDO::ATTR_PERSISTENT => true, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); $sth = $db->query('use test_database'); $sth = $db->prepare('select * from fukens'); $sth->execute(array()); while ($line = $sth->fetch()) { var_dump($line); } exit;
public function install($ctn) { if (!$ctn['config']['installed']) { $msg = ""; // no sec here, just install if ($_REQUEST['action'] == 'save') { $file = $ctn['pathApp'] . "config.json"; $config = $ctn['config']; // update DB settings $config['database']['name'] = $_REQUEST['db_name']; $config['database']['user'] = $_REQUEST['db_user']; $config['database']['pass'] = $_REQUEST['db_pass']; $config['database']['host'] = $_REQUEST['db_host']; $config['database']['port'] = $_REQUEST['db_port']; unset($config['database']['nodatabase']); // set basic data $config['url'] = $_REQUEST['url']; $config['site'] = preg_replace("/[^0-9a-zA-Z_\\s]+/", "", $_REQUEST['url']); $config['salt'] = md5(time() . rand(10, 20)); // connect to database (with new parameters) try { $db = new pdo('mysql:host=' . $_REQUEST['db_host'] . ':' . $_REQUEST['db_port'] . ';dbname=' . $_REQUEST['db_name'], $_REQUEST['db_user'], $_REQUEST['db_pass']); // install mysql structure $structureFile = $ctn['pathApp'] . "database.sql"; if (!file_exists($structureFile)) { $msg = "Could not fine database file"; } else { $cmd = file_get_contents($structureFile); $sth = $db->prepare($cmd); $sth->execute(); // create user $sth = $db->prepare("INSERT INTO user (role_id,username,password) VALUES (3,:user,:pass); "); $sth->bindValue("user", $_REQUEST['user']); $sth->bindValue("pass", password_hash($_REQUEST['pass'] . $config['salt'], PASSWORD_BCRYPT, array('cost' => 12))); $sth->execute(); $config['installed'] = true; $json = json_encode($config, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); file_put_contents($file, $json); apcu_clear_cache(); header("Location: /"); } } catch (\PDOException $e) { $msg = $e->getMessage(); } } ?> <form action="/"> <input type="hidden" name="action" value="save" /> <h1>Install</h1> <h2>Website Settings</h2> <table> <tr> <td>URL:</td> <td><input type="text" name="url" value="<?php echo $_REQUEST['url']; ?> " /></td> </tr> <tr> <td>Username:</td> <td><input type="text" name="user" value="<?php echo $_REQUEST['user']; ?> " /></td> </tr> <tr> <td>Password:</td> <td><input type="password" name="pass" value="<?php echo $_REQUEST['pass']; ?> " /></td> </tr> </table> <h2>Database Settings</h2> <p style='color: red;'><?php echo $msg; ?> </p> <table> <tr> <td>DB-Name:</td> <td><input type="text" name="db_name" value="<?php echo $_REQUEST['db_name']; ?> " /></td> </tr> <tr> <td>Username:</td> <td><input type="text" name="db_user" value="<?php echo $_REQUEST['db_user']; ?> " /></td> </tr> <tr> <td>Password:</td> <td><input type="password" name="db_pass" value="<?php echo $_REQUEST['db_pass']; ?> " /></td> </tr> <tr> <td>Host:</td> <td><input type="text" name="db_host" value="<?php echo $_REQUEST['db_host']; ?> " /></td> </tr> <tr> <td>Port:</td> <td><input type="text" name="db_port" value="<?php echo $_REQUEST['db_port']; ?> " /></td> </tr> </table> <p> <input type="submit" value="Install"> </p> </form> <?php die; } }
/** * Removes a lock from a uri * * @param string $uri * @param Sabre_DAV_Locks_LockInfo $lockInfo * @return bool */ public function unlock($uri, Sabre_DAV_Locks_LockInfo $lockInfo) { $stmt = $this->pdo->prepare('DELETE FROM locks WHERE uri = ? AND token = ?'); $stmt->execute(array($uri, $lockInfo->token)); return $stmt->rowCount() === 1; }
$_SESSION["errorMsg"] = ""; } /* * Session verification. If no session value page redirect to login.php */ $mode = $_REQUEST["mode"]; if ($mode == "login") { $username = trim($_POST['username']); $pass = trim($_POST['user_password']); if ($username == "" || $pass == "") { $_SESSION["errorType"] = "danger"; $_SESSION["errorMsg"] = "Enter manadatory fields"; } else { $sql = "SELECT * FROM system_users WHERE u_username = :uname AND u_password = :upass "; try { $stmt = $DB->prepare($sql); // bind the values $stmt->bindValue(":uname", $username); $stmt->bindValue(":upass", md5($pass)); // execute Query $stmt->execute(); $results = $stmt->fetchAll(); if (count($results) > 0) { $_SESSION["errorType"] = "success"; $_SESSION["errorMsg"] = "You have successfully logged in."; $_SESSION["user_id"] = $results[0]["u_userid"]; $_SESSION["rolecode"] = $results[0]["u_rolecode"]; $_SESSION["username"] = $results[0]["u_username"]; $_SESSION["name"] = $results[0]["u_name"]; $_SESSION['timeout'] = time(); header("Location:dashboard.php");
<?php if (isset($_POST["submit"])) { try { $db = new pdo('mysql:host=localhost;dbname=bieren', 'root', ''); // Root password not set up $message = "db init"; $brNaam = $_POST["brouwernaam"]; $adres = $_POST["adres"]; $postcode = $_POST["postcode"]; $gemeente = $_POST["gemeente"]; $omzet = $_POST["omzet"]; $insertQuery = "INSERT INTO brouwers (brnaam, adres, postcode, gemeente, omzet) VALUES('{$brNaam}','{$adres}','{$postcode}','{$gemeente}','{$omzet}');"; // var_dump("INSERT INTO brouwers (brnaam, adres, postcode, gemeente, omzet) VALUES(" . $brNaam . ", " . $adres . ", ". $postcode . ", " . $gemeente . ", " . $omzet . ");"); $statement = $db->prepare($insertQuery); $isAdded = $statement->execute(); if ($isAdded) { $id = $db->lastInsertId(); // Returns id of the last inserted row $message = 'Brouwerij succesvol toegevoegd. Het unieke nummer van deze brouwerij is ' . $id . '.'; } else { $message = 'Er ging iets mis met het toevoegen, probeer opnieuw'; } } catch (PDOException $e) { $message = 'De connectie is niet gelukt.'; } } ?> <!doctype html> <html>
} // verwijderen $teVerwijderen = ''; if (isset($_GET['delete'])) { $_SESSION['teVerwijderen'] = $_GET['delete']; } if (isset($_SESSION['teVerwijderen'])) { $teVerwijderen = $_SESSION['teVerwijderen']; } if (isset($_GET['bevestiging'])) { if ($_GET['bevestiging'] == 'ja') { $verwijderQuery = 'DELETE FROM brouwers WHERE brouwernr = :teVerwijderen'; //echo('Query: <code> ' . $verwijderQuery . '</code>') ; try { $statement = $db->prepare($verwijderQuery); $statement->bindValue(':teVerwijderen', $teVerwijderen); $statement->execute(); $boodschap = 'De datarij werd goed verwijderd'; } catch (PDOException $e) { $boodschap = 'De datarij kon niet verwijderd worden. Probeer opnieuw.'; } $_SESSION['teVerwijderen'] = ''; $teVerwijderen = ''; } else { header("Location: {$ditBestand}"); $_SESSION['teVerwijderen'] = ''; $teVerwijderen = ''; } } // edit
/** * 执行 * @param string $query * @param string $parameters */ protected function execute($query, $parameters = "") { try { $this->sQuery = $this->pdo->prepare($query); $this->bindMore($parameters); if (!empty($this->parameters)) { foreach ($this->parameters as $param) { $parameters = explode("", $param); $this->sQuery->bindParam($parameters[0], $parameters[1]); } } $this->succes = $this->sQuery->execute(); } catch (\PDOException $e) { // 服务端断开时重连一次 if ($e->errorInfo[1] == 2006 || $e->errorInfo[1] == 2013) { $this->closeConnection(); $this->connect(); try { $this->sQuery = $this->pdo->prepare($query); $this->bindMore($parameters); if (!empty($this->parameters)) { foreach ($this->parameters as $param) { $parameters = explode("", $param); $this->sQuery->bindParam($parameters[0], $parameters[1]); } } $this->succes = $this->sQuery->execute(); } catch (\PDOException $ex) { $this->rollBackTrans(); throw $ex; } } else { $this->rollBackTrans(); throw $e; } } $this->parameters = array(); }
/** * Scan e carga para banco SQL, dos XMLs dispostos em filesystem. Ver scripts "ini.sql". */ // // // // // CONFIGURACOES: $PG_USER = '******'; $PG_PW = 'pp@123456'; $pasta = '/home/peter/Área de Trabalho/hackday/xml-scielo'; $n = 0; $dsn = "pgsql:dbname=postgres;host=localhost"; $db = new pdo($dsn, $PG_USER, $PG_PW); $XHEAD = ''; // $XHEAD = '<?xml version="1.0" encoding="UTF-8" >'."\n"; $rgx_doctype = '/^\\s*<!DOCTYPE\\s([^>]+)>/s'; // INSERT de teste com as ~2mil amostras do SciELO-BR $stmt = $db->prepare("INSERT INTO articles(repo,repos_pid,content_dtd,xcontent) VALUES (1,:pid,:doctype,:conteudo)"); foreach (scandir($pasta) as $file) { if (strlen($file) > 5) { // && $n<10 $n++; print "\n -- {$file}"; $pid = str_replace('.xml', '', $file); $cont = file_get_contents("{$pasta}/{$file}"); $stmt->bindParam(':pid', $pid, PDO::PARAM_STR); $doctype = preg_match($rgx_doctype, $cont, $m) ? $m[1] : ''; if ($doctype) { $cont = preg_replace($rgx_doctype, '', $cont); } $stmt->bindParam(':doctype', $doctype, PDO::PARAM_STR); // $stmt->bindParam(':conteudo',$XHEAD.$cont,PDO::PARAM_STR); $stmt->bindParam(':conteudo', $cont, PDO::PARAM_STR);
/** * Submit request (cmd with params) to the database. As webservice. * @param $cmd string command * @param $params array, params of the command. * @param $degVers int openness degree version. * @param $notRetJson int 0=JSON, 1=PHP ARRAY, 2=PHP OBJECTS. */ function request_ws($cmd, $params, $degVers = 2, $notRetJson = 0) { global $dsn; global $PG_USER; global $PG_PW; $err_cod = 0; try { $jinfo = json_encode($params); switch ($cmd) { case 'licqts_calc': $sql = "SELECT om.licqts_calc(:j_info::json,{$degVers})"; break; case 'famqts_calc': $sql = "SELECT om.famqts_calc(:j_info::json,{$degVers})"; break; default: throw new Exception("Comando '{$cmd}' desconhecido", 5); } $db = new pdo($dsn, $PG_USER, $PG_PW); $stmt = $db->prepare($sql); if ($stmt->bindParam(":j_info", $jinfo)) { $ok = $stmt->execute(); } else { throw new Exception("Falha no bindParam", 8); } if ($ok) { $json = $stmt->fetchColumn(); return $notRetJson ? json_decode($json, $notRetJson == 2 ? false : true) : $json; } else { throw new Exception("Falha ao executar SQL, \n'''{$sql}'''\n", 20); } return null; //never here } catch (Exception $e) { $r = array('error' => array('code' => $e->getCode(), 'message' => $e->getMessage())); } return $notRetJson ? $r : json_encode($r, true); }
<?php session_start(); if (isset($_POST['login'])) { $email = $_POST['email']; $password = $_POST['password']; try { $db = new pdo('mysql:host=localhost;dbname=users-fileupload', 'root', ''); $query = "SELECT * FROM users WHERE email = '{$email}'"; $statement = $db->prepare($query); $statement->execute(); // Tel hoeveel rijen de query returnt $results = $statement->rowCount(); if ($results != 0) { // Als er een match is met de database $resultsArray = array(); while ($row = $statement->fetch(PDO::FETCH_ASSOC)) { $resultsArray[] = $row; } // Get database values $salt = $resultsArray[0]['salt']; $hashedDbPassword = $resultsArray[0]['hashed_password']; // Get form values -> hash $saltedPassword = $salt . $password; $hashedPassword = hash('sha256', $saltedPassword); if ($hashedPassword == $hashedDbPassword) { $_SESSION['message'] = "U bent ingelogd."; $updateTimeQuery = "UPDATE users SET last_login_time=NOW() WHERE email = '{$email}'"; $updateTime = $db->prepare($updateTimeQuery); $updateTime->execute(); setcookie("login", $email . "," . $salt, time() + 86400 * 30);
<?php session_start(); require_once 'google/appengine/api/cloud_storage/CloudStorageTools.php'; use google\appengine\api\cloud_storage\CloudStorageTools; $username = $_SESSION['user']; echo $username; $db = new pdo('mysql:unix_socket=/cloudsql/assignment7-1001:assgn7;dbname=scale', 'root', 'shweta'); $fetchData = $db->prepare("select * from images where username = '******' "); $fetchData->execute(); echo "<table border='2'>"; echo '<tr>'; echo '<th>FileName:</th>'; echo '<th>Image:</th>'; echo '<th>FileSize:</th>'; echo '<th>FileURL:</th>'; echo '</tr>'; while ($row = $fetchData->fetch()) { $filename = $row['filename']; $filesize = $row['filesize']; $fileurl = $row['fileurl']; echo '<tr>'; echo '<td>' . $filename . '</td>'; echo '<td>' . $filesize . '</td>'; echo '<td>'; echo "<img src='" . $fileurl . "'></img><form action = 'delete.php' method='POST' ><input type='submit' name= 'submit' value='delete'>"; if (isset($_POST['delete'])) { $delete = $db->prepare("delete from images where fileurl = '{$fileurl}'"); $delete->exceute(); } echo '</form>';
} generatePassword(); // Ga terug naar het registratieformulier header('location: registratie-form.php'); } if (isset($_POST['registreer'])) { try { $db = new pdo('mysql:host=localhost;dbname=users-fileupload', 'root', ''); if (isset($_POST['email']) && isset($_POST['password'])) { $_SESSION['email'] = $_POST['email']; $email = $_POST['email']; $isEmail = filter_var($email, FILTER_VALIDATE_EMAIL); // Check of email valid is if ($isEmail) { $checkEmailQuery = "SELECT * FROM `users` WHERE email = '{$email}'"; $checkEmailInDB = $db->prepare($checkEmailQuery); $checkEmailInDB->execute(); $isInDB = $checkEmailInDB->fetch(PDO::FETCH_ASSOC); // Returnt false als de email als de query geen resultaten teruggeeft. if ($isInDB) { $_SESSION['message'] = "De email staat al in de database."; } else { // Als de email nog niet in de database zit $salt = uniqid(mt_rand(), true); $password = $salt . $_POST['password']; $hashedPw = hash('sha256', $password); $query = "INSERT INTO users (email, salt, hashed_password, last_login_time) VALUES('{$email}', '{$salt}', '{$hashedPw}', CURRENT_TIMESTAMP)"; $insert = $db->prepare($query); $insert->execute(); setcookie("login", $email . "," . $salt, time() + 86400 * 30); // Set cookie voor 30 dagen
DELETE FROM oc.license_families; '; // // // // INITS: $db = new pdo($dsn, $PG_USER, $PG_PW); $stmt = $db->exec($sql_delete); $SEP = ','; $nmax = 0; // 0 or debug with ex. 10 $n = 0; foreach ($items as $prj => $r) { foreach ($r as $dataset) { $folder = $projects[$prj]; $sql = array_shift($dataset); print "\n\n---- PRJ {$prj} {{ {$sql} }}"; $stmt = $db->prepare($sql); $jpack = json_decode(file_get_contents("{$folder}/datapackage.json"), true); $ds = array(); // only for "bind check". foreach ($dataset as $i) { $i = str_replace('::bind', '', $i, $bind); $ds["data/{$i}"] = $bind; } $ds_keys = array_keys($ds); foreach ($jpack['resources'] as $pack) { if (in_array($pack['path'], $ds_keys)) { print "\n\t-- reding dataset '{$pack['path']}' "; $fields = $pack['schema']['fields']; list($sql_fields, $json_fields) = fields_to_parts($fields, false); $n = $n2 = 0; $nsql = count($sql_fields);
<?php session_start(); if (isset($_POST['submit'])) { $_SESSION['titel'] = $_POST['titel']; $_SESSION['artikel'] = $_POST['artikel']; $_SESSION['kernwoorden'] = $_POST['kernwoorden']; $_SESSION['datum'] = $_POST['datum']; try { $db = new pdo('mysql:host=localhost;dbname=opdracht_mod_rewrite_blog', 'root', '', array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)); $queryString = "insert into artikels\n (Titel,Artikel,Kernwoorden,Datum)\n values\n (:Titel,:Artikel,:Kernwoorden,:Datum)"; $statement = $db->prepare($queryString); $statement->bindValue(':Titel', $_POST['titel']); $statement->bindValue(':Artikel', $_POST['artikel']); $statement->bindValue(':Kernwoorden', $_POST['kernwoorden']); $statement->bindValue(':Datum', $_POST['datum']); $gelukt = $statement->execute(); if ($gelukt) { $_SESSION['notification'] = 'Het artikel werd toegevoegd.'; header('location:artikel-overzicht.php'); } else { $_SESSION['notification'] = 'Er ging iets mis bij het toevoegen. Gelieve alle velden juist in te vullen.'; header('location:artikel-toevoegen-form.php'); } } catch (PDOException $e) { $_SESSION['notification'] = 'Er ging iets mis: ' . $e->getmessage(); } }
<?php $pdo = new pdo("mysql:host=localhost;dbname=ders", "root", ""); $sorgu = $pdo->prepare("select * from ders") or die("Hata: " . $pdo->errorInfo()[2]); $sorgu->execute(); foreach ($sorgu as $veri) { echo $veri[1]; }
public function prepare($sql) { if ($this->path_log_file) { file_put_contents($this->path_log_file, $sql . "\n\n", FILE_APPEND); } ++$this->querycount; return parent::prepare($sql); }
$artikel = $_POST["artikel"]; $_SESSION["artikel"] = $artikel; } if (isset($_POST["kernwoorden"])) { $kernwoorden = $_POST["kernwoorden"]; $_SESSION["kernwoorden"] = $kernwoorden; } if (isset($_POST["datum"])) { $datum = $_POST["datum"]; $_SESSION["datum"] = $datum; } if (!empty($_POST["titel"]) && !empty($_POST["artikel"]) && !empty($_POST["kernwoorden"]) && !empty($_POST["datum"])) { try { $db = new pdo('mysql:host=localhost;dbname=opdracht_blog', 'root', ''); $insertQuery = "INSERT INTO artikels(titel, artikel, kernwoorden, datum) VALUES (:titel, :artikel, :kernwoorden, :datum)"; $insert = $db->prepare($insertQuery); $insert->bindParam(':titel', $titel, PDO::PARAM_STR); $insert->bindParam(':artikel', $artikel, PDO::PARAM_STR); $insert->bindParam(':kernwoorden', $kernwoorden, PDO::PARAM_STR); $insert->bindParam(':datum', $datum, PDO::PARAM_STR); $insert->execute(); $_SESSION["notification"] = "Artikel toegevoegd aan de database!"; header('location: artikels-overzicht.php'); } catch (PDOException $se) { $_SESSION["notification"] = "Er ging iets mis bij het toevoegen van het artikel aan de database. Error " . $e . "."; header('location: artikel-toevoegen-form.php'); } } else { $_SESSION["notification"] = "Gelieve alle velden in te vullen!"; header('location: artikel-toevoegen-form.php'); }
session_start(); $link = str_replace(basename(__FILE__), '', $_SERVER['REQUEST_URI']); $zoekterm = ''; $jaar = 2010; $fetchRow = array(); $message = ''; if (isset($_SESSION['notification'])) { $message = $_SESSION['notification']; unset($_SESSION['notification']); } try { $db = new pdo('mysql:host=localhost;dbname=opdracht_mod_rewrite_blog', 'root', '', array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)); if (isset($_GET['zoekInArtikel'])) { $zoekterm = 'artikels die het woord "' . $_GET['artikel'] . '" bevatten'; $zoekArtikelQueryString = "Select * from artikels\n WHERE artikel LIKE :artikel"; $statement2 = $db->prepare($zoekArtikelQueryString); $statement2->bindValue(':artikel', '%' . $_GET['artikel'] . '%'); $statement2->execute(); $fetchRow = array(); while ($row = $statement2->fetch(PDO::FETCH_ASSOC)) { $fetchRow[] = $row; } } if (isset($_GET['zoekOpDatum'])) { $jaar = $_GET['jaar']; $zoekterm = 'artikels geschreven in "' . $_GET['jaar'] . '"'; $zoekOpDatumQueryString = "Select * from artikels\n WHERE year(Datum) = :jaar"; $statement3 = $db->prepare($zoekOpDatumQueryString); $statement3->bindValue(':jaar', $_GET['jaar']); $statement3->execute(); $fetchRow = array();
<?php $message = ""; try { $db = new pdo('mysql:host=localhost;dbname=bieren', 'root', ''); // Root password not set up $message = "DB init"; } catch (PDOException $e) { $message = $e->getMessage(); } // Query for dropdown menu $query = "SELECT brnaam AS Brouwerij FROM brouwers;"; $statement = $db->prepare($query); // Een query uitvoeren $statement->execute(); if (isset($_GET["select"])) { } $resultsArray = array(); while ($value = $statement->fetch(PDO::FETCH_ASSOC)) { $resultsArray[] = $value; // Lijst met brouwernummers } $columnTitle = array(); $columnTitle[] = "#"; // Get all column titles from DB foreach ($resultsArray[0] as $key => $value) { $columnTitle[] = $key; } //var_dump($resultsArray); ?>
header('location: gegevens-wijzigen-form.php'); } } else { $_SESSION['message'] = "ERROR. De file is geen jpeg/gif/png bestand. Het is een " . $typeBestand . " bestand."; } } else { $_SESSION['message'] = "Er werd geen nieuwe profielfoto geselecteerd"; } if (isset($_POST['updateEmail'])) { $updatedEmail = $_POST['updateEmail']; $isEmail = filter_var($updatedEmail, FILTER_VALIDATE_EMAIL); if ($isEmail) { if ($currentEmail != $updatedEmail) { $db = new pdo('mysql:host=localhost;dbname=users-fileupload', 'root', ''); $updateEmailQuery = "UPDATE users SET email='{$updatedEmail}' WHERE email='{$currentEmail}';"; $updateEmail = $db->prepare($updateEmailQuery); $updateEmail->execute(); setcookie("login", time() - 500); setcookie("login", $updatedEmail, time() + 86400 * 30); $_SESSION['message'] = "Emailadres werd gewijzigd naar " . $updatedEmail; } else { $_SESSION['message'] = "Het emailadres werd niet veranderd. Huidig emailadres: |" . $currentEmail . " | Nieuw emailadres: |" . $updatedEmail . " | En de cookievalue zegt: |" . $getCookie[0] . "|"; } } else { $_SESSION['message'] = "Dit is geen emailadres."; } } else { $_SESSION['message'] = "Je moet een emailadres opgeven."; } } header('location: gegevens-wijzigen-form.php');
echo $fileName . "<br>"; $options = array('gs' => array('acl' => 'public-read', 'Content-Type' => $_FILES['uploaded_file']['type'])); $ctx = stream_context_create($options); if (false == rename($_FILES['uploaded_file']['tmp_name'], $fileName, $ctx)) { die('Could not rename.'); } $object_public_url = CloudStorageTools::getPublicUrl($fileName, true); echo $object_public_url . "<br>"; $filename = $_FILES['uploaded_file']['name']; echo $filename . "<br>"; $filesize = $_FILES['uploaded_file']['size']; echo $filesize . "<br>"; $db = new pdo('mysql:unix_socket=/cloudsql/assignment7-1001:assgn7;dbname=scale', 'root', 'shweta'); $username = $_SESSION['user']; echo $username; $insertStatememt = $db->prepare("insert into images values('{$username}','{$filename}','{$filesize}','{$object_public_url}')"); $insertStatememt->execute(); $stm = $db->prepare("select * from images"); $stm->execute(); // Displaying all the uploaded files in a web page. echo "<table border='2'>"; echo '<tr>'; echo '<th>FileName:</th>'; echo '<th>Image:</th>'; echo '<th>FileSize:</th>'; echo '<th>FileURL:</th>'; echo '</tr>'; while ($row = $stm->fetch()) { $filename = $row['filename']; $filesize = $row['filesize']; $fileurl = $row['fileurl'];
/** * Removes a lock from a uri * * @param string $uri * @param LockInfo $lockInfo * @return bool */ function unlock($uri, LockInfo $lockInfo) { $stmt = $this->pdo->prepare('DELETE FROM ' . $this->tableName . ' WHERE uri = ? AND token = ?'); $stmt->execute([$uri, $lockInfo->token]); return $stmt->rowCount() === 1; }
<?php try { $bdd = new pdo('mysql:host=localhost;dbname=espacemembres;charset=utf8', 'root', ''); } catch (Exception $e) { die('Erreur : ' . $e->getMessage()); } //hachage du mote de passe $pass_hache = sha1($_POST['pass']); //Vérification des identifiants $req = $bdd->prepare('SELECT id FROM membres WHERE pseudo = :pseudo AND pass = :pass'); $req->execute(array(':pseudo' => $_POST['pseudo'], ':pass' => $pass_hache)); $resultat = $req->fetch(); if (!$resultat) { echo 'identifiant et/ou mot de passe incorrect(s) !'; } else { session_start(); $_SESSION['id'] = $resultat['id']; $_SESSION['pseudo'] = $pseudo; echo 'Vous êtes connecté'; }
$ctx = stream_context_create($options); if (false == rename($_FILES['uploaded_files']['tmp_name'], $fileName, $ctx)) { die('Could not rename.'); } // $var2 =(new \ DateTime())->format('i:s'); $object_public_url = CloudStorageTools::getPublicUrl($fileName, true); $var1 = date("Y-m-d H:i:s"); $var2 = microtime(true); $var3 = $var2 - $var1; // echo $var3; // echo $object_public_url."<br>"; // print $thisfile; // print $thatfile; // var_dump($_FILES); $db = new pdo('mysql:unix_socket=/cloudsql/ordinal-gear-93506:testdb;dbname=g1', 'root', ''); $stmt1 = $db->prepare("select * from another where filename='{$thatfile}'"); $stmt1->execute(); $row = $stmt1->fetch(); if ($row > 0) { echo "duplicate entry"; // $db->exec("insert into users values('8975','200')"); } else { $db->exec("insert into another values('','{$thatfile}','{$var6}','{$object_public_url}','{$var1}')"); // $db->exec("insert into finaltest values('','$thatfile','filesize($thisfile)','$object_public_url','$var3')"); $stmt = $db->prepare("select * from another ORDER BY filesize;"); $stmt->execute(); echo "<table border='2'>"; echo '<tr>'; echo '<th>ID:</th>'; echo '<th>FileName:</th>'; echo '<th>FileSize:</th>';
*/ echo "this is a shop_cart test.\n"; $ip = '127.0.0.1'; $port = '3306'; $user = '******'; $pass = ''; $info = sprintf("mysql:host=%s;port=%s,database=;", $ip, $port); $db = new pdo($info, $user, $pass, array(PDO::ATTR_PERSISTENT => true, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); $db->query('use shop_cart'); /* $sth = $db->prepare('select * from user'); $sth->execute(array()); $user = array(); while ($line = $sth->fetch()) { $user[$line['id']] = $line; } $sth->closeCursor(); */ $sth_buy = $db->prepare('select * from buy'); $sth_buy_item = $db->prepare('select * from buy_item where buycd = ?'); $sth_item_list = $db->prepare('select * from item_list where itemcd= ?'); $sth_user = $db->prepare('select * from user where id = ?'); $sth_buy->execute(array()); while ($line_buy = $sth_buy->fetch()) { print $line_buy['buycd']; print $line_buy['buy_date']; } $sth_buy->closeCursor(); exit;