/** * (non-PHPdoc) * @see IUserLoginMethod::authenticateWithEmail() */ public function authenticateWithEmail($email, $password) { // connect to a data base // Note: If your source application shares the same data base, you can simply use $this->_db, rather than open another connection. $mysqli = new mysqli($this->_websoccer->getConfig('db_host'), $this->_websoccer->getConfig('db_user'), $this->_websoccer->getConfig('db_passwort'), $this->_websoccer->getConfig('db_name')); // get user from your source table $escapedEMail = $mysqli->real_escape_string($email); $dbresult = $mysqli->query('SELECT password FROM mydummy_table WHERE email = \'' . $escapedEMail . '\''); if (!$dbresult) { throw new Exception('Database Query Error: ' . $mysqli->error); } $myUser = $dbresult->fetch_array(); $dbresult->free(); $mysqli->close(); // could not find user if (!$myUser) { return FALSE; } // check is password is correct (in this sample case a simple MD5 hashing is applied). if ($myUser['password'] != md5($password)) { return FALSE; } // user is valid user according to custom authentication check. Now test if user already exists in local DB and return its ID. $existingUserId = UsersDataService::getUserIdByEmail($this->_websoccer, $this->_db, strtolower($email)); if ($existingUserId > 0) { return $existingUserId; } // if user does not exist, create a new one. Nick name can be entered by user later. return UsersDataService::createLocalUser($this->_websoccer, $this->_db, null, $email); }
function getMailData() { $mysqli = new mysqli($GLOBALS["servername"], $GLOBALS["server_username"], $GLOBALS["server_password"], $GLOBALS["database"]); $stmt = $mysqli->prepare("SELECT comment_id, user_id, text FROM eksam_comment WHERE send_email = ?"); $stmt->bind_param("s", $_SESSION["user_email"]); $stmt->bind_result($comment_id, $id_mail, $text); $stmt->execute(); // tühi massiiv kus hoiame objekte (1 rida andmeid) $array = array(); // tee tsüklit nii mitu korda, kui saad // ab'ist ühe rea andmeid while ($stmt->fetch()) { // loon objekti iga while tsükli kord $mail = new StdClass(); $mail->comment_id = $comment_id; $mail->id_mail = $id_mail; $mail->text = $text; // lisame selle massiivi array_push($array, $mail); //echo "<pre>"; //var_dump($array); //echo "</pre>"; } $stmt->close(); $mysqli->close(); return $array; }
function handle_login() { $username = $_POST['username']; $password = $_POST['password']; require_once 'db.conf'; $mysqli = new mysqli($dbhost, $dbuser, $dbpass, $dbname); if ($mysqli->connect_error) { $error = 'Error: ' . $mysqli->connect_errno . ' ' . $mysqli->connect_error; require "login_form.php"; exit; } $username = $mysqli->real_escape_string($username); $password = $mysqli->real_escape_string($password); $query = "SELECT * FROM users WHERE username = '******' AND password = '******'"; $mysqliResult = $mysqli->query($query); // print_r(mysqli_fetch_all($mysqliResult,MYSQLI_ASSOC)); if ($mysqliResult) { $match = $mysqliResult->num_rows; $mysqliResult->close(); $mysqli->close(); //print "The match is $match"; if ($match == 1) { $_SESSION['loggedin'] = $username; header("Location: home.php"); exit; } else { $error = "Incorrect username or password"; require "login_form.php"; exit; } } }
function modificaCoche($coche) { //alert($coche->login); global $servidor, $bd, $usuario, $contrasenia; try { @($db = new mysqli($servidor, $usuario, $contrasenia)); if (mysqli_connect_errno() != 0) { throw new Exception('Error conectando:' . mysqli_connect_error(), mysqli_connect_errno()); } $db->select_db($bd); if ($db->errno != 0) { throw new Exception('Error seleccionando bd:' . $db->error, $db->errno); } $consulta = "update coches set marca='" . $coche->marca . "', modelo='" . $coche->modelo . "', color='" . $coche->color . "' where matricula='" . $coche->matricula . "'"; if ($db->query($consulta) === false) { throw new ExcepcionEnTransaccion(); } $db->commit(); $db->close(); } catch (ExcepcionEnTransaccion $e) { echo 'No se ha podido realizar la modificacion'; $db->rollback(); $db->close(); } catch (Exception $e) { echo $e->getMessage(); if (mysqli_connect_errno() == 0) { $db->close(); } exit; } }
function db_connect() { global $MYSQL_HOST; global $MYSQL_USER; global $MYSQL_PASS; $mysqli = new mysqli($MYSQL_HOST, $MYSQL_USER, $MYSQL_PASS); if ($mysqli->connect_errno) { print "<b>Failed to connect to MySQL: " . $mysqli->connect_error . "</b><br/>\n"; return FALSE; } if ($mysqli->select_db("trees") === FALSE) { print "<b>select_db() failed</b><br/>\n"; $mysqli->close(); return FALSE; } $result = $mysqli->query("SELECT DATABASE()"); if ($result !== FALSE) { $row = $result->fetch_row(); if ($row[0] != "trees") { print "<b>Unable to select database</b><br/>\n"; $mysqli->close(); return FALSE; } } else { print "<b>SELECT DATABASE() failed</b><br/>\n"; $mysqli->close(); return FALSE; } return $mysqli; }
function loadData($request) { global $hostname_ISANdb; global $database_ISANdb; global $username_ISANdb; global $password_ISANdb; $mysqli = new mysqli($hostname_ISANdb, $username_ISANdb, $password_ISANdb, $database_ISANdb); if ($mysqli->connect_error) { die('Connect Error (' . $mysqli->connect_errno . ') ' . $mysqli->connect_error); } $mysqli->query("SET NAMES 'UTF8'"); if ($request == "person") { if ($stmt = $mysqli->prepare("SELECT id, firstName, lastName, patrName FROM `{$request}` WHERE 1")) { $stmt->execute(); $stmt->bind_result($id, $fname, $lname, $pname); while ($stmt->fetch()) { $result .= "<option value=\"{$id}\">{$lname} {$fname} {$pname}</option>"; } $mysqli->close(); return $result; } } if ($stmt = $mysqli->prepare("SELECT id, name FROM `{$request}` WHERE 1")) { $stmt->execute(); $stmt->bind_result($id, $name); $result = "<option value=\"0\">Не выбрано</option>"; while ($stmt->fetch()) { $result .= "<option value=\"{$id}\">{$name}</option>"; } $mysqli->close(); return $result; } }
public function checkUserLoginServe($input) { //email, pass // dd(444); // $this->query = DB::connection('main_store'); // $pdo = DB::connection('main_store')->getPdo(); $conn = new mysqli('localhost', 'root', 'root', 'main_store'); if ($conn->connect_error) { dd(5666); } $email = $input['email']; $password = $input['password']; $sql = "SELECT id, url, session_id FROM users WHERE email = '{$email}' and password ='******' "; $result = $conn->query($sql); if ($result->num_rows > 0) { $row = $result->fetch_assoc(); // dd($row['url']); // $conn->close(); // dd(11); return $row['url']; // dd($result->fetch_assoc()); } $conn->close(); // // dd(123); // throw new Prototype\Exceptions\UserLoginException(); // if (Auth::user()->attempt(Input::only('email', 'password'))){ // $userId = Auth::user()->get()->id; // $sessionId = Common::getSessionId(Input::all(), $userId); // //check database // return Common::returnData(200, SUCCESS, $userId, $sessionId); // } }
function modificaAlumno($alumno) { global $servidor, $bd, $usuario, $contrasenia; try { @($db = new mysqli($servidor, $usuario, $contrasenia)); if (mysqli_connect_errno() != 0) { throw new Exception('Error conectando:' . mysqli_connect_error(), mysqli_connect_errno()); } $db->select_db($bd); if ($db->errno != 0) { throw new Exception('Error seleccionando bd:' . $db->error, $db->errno); } $consulta = "update alumnos set password='******', nombre='" . $alumno->nombre . "', apellido='" . $alumno->apellido . "', dni='" . $alumno->dni . "', email='" . $alumno->email . "', telefono=" . $alumno->telefono . ", sexo='" . $alumno->sexo . "' where login='******'"; if ($db->query($consulta) === false) { throw new ExcepcionEnTransaccion(); } $db->commit(); $db->close(); } catch (ExcepcionEnTransaccion $e) { echo 'No se ha podido realizar la modificacion'; $db->rollback(); $db->close(); } catch (Exception $e) { echo $e->getMessage(); if (mysqli_connect_errno() == 0) { $db->close(); } exit; } }
function auth($username, $password) { // Create connection $mysqli = new mysqli($servername, $user, $passwd, $database); // Check connection if ($mysqli->connect_error) { die("Connection failed: " . $mysqli->connect_error); } if ($stmt = $mysqli->prepare("SELECT COUNT(*), wa_nickname, wa_number, wa_key FROM config where username = ? and password = ?;")) { $stmt->bind_param("ss", $username, $password); $stmt->execute(); $stmt->bind_result($userCount, $wa_nickname, $wa_number, $wa_key); $stmt->fetch(); if ($userCount == 1) { $_SESSION['wa_nickname'] = $wa_nickname; $_SESSION['wa_number'] = $wa_number; $_SESSION['wa_key'] = $wa_key; $stmt->close(); $mysqli->close(); return true; } else { $stmt->close(); $mysqli->close(); return false; } } return false; }
public function Find() { $myDBConnector = new DBConnector(); $dbARY = $myDBConnector->infos(); $myQuery = "SELECT MAX(usedID) FROM usedIDs"; $connection = new mysqli($dbARY[0], $dbARY[1], $dbARY[2], $dbARY[3]); if ($connection->connect_error) { return -1; } /* database'e girdik */ $result = $connection->query($myQuery); if ($result->num_rows != 0) { $curResult = $result->fetch_assoc(); $newResult = $curResult["MAX(usedID)"]; $newResult = (int) $newResult; $newResult = $newResult + 1; } else { $newResult = 1; } if ($connection->query("INSERT INTO usedIDs(usedID) VALUES (" . $newResult . ")") === TRUE) { $connection->close(); return $newResult; } $connection->close(); return -1; }
public function closeConnection() { if ($this->isConnected()) { $this->connected = false; $this->mysqli->close(); } }
/** * Closes the current DB connection */ public function closeConn() { if (!isset($this->_conn)) { return; } $this->_conn->close(); }
public function Uninit() { if ($this->connection) { $this->connection->close(); $this->connection = null; } }
public function close() { if ($this->connection !== NULL) { // mysql_close($this->connection); $this->connection->close(); $this->connection = NULL; } }
/** * Connection destructor */ public function __destruct() { if (isset($this->mysqli) && !$this->mysqli->connect_error) { $threadId = $this->mysqli->thread_id; $this->mysqli->kill($threadId); $this->mysqli->close(); } }
public static function disconnect() { if (static::$_connected || static::$_mysqli !== null) { static::$_mysqli->close(); static::$_mysqli = null; static::$_connected = false; } }
function mysql_close_link() { if (is_object($this->link)) { $this->link->close(); $this->connected = false; unset($this->link); } return true; }
/** * Shuts down a Sql connection * * @return Boolean */ public function disconnect() { if (isset($this->_resource)) { $ret = $this->_resource->close(); unset($this->_resource); return $ret; } return false; }
/** * Destructor de la clase, nos aseguramos de desconectar la base de datos. */ public function __destruct() { // Verificamos desconección. if ($this->dbh !== NULL) { @$this->dbh->close(); } // Destruimos el objeto. $this->dbh = NULL; unset($this); }
public function disconnect() { if ($this->mysqli) { $result = $this->mysqli->close(); if (!$result) { throw new Database\Exception('Disconnect failed', Database\Exception::DISCONNECT_ERROR); } else { $this->mysqli = null; } } }
public function close() { if (!$this->connected) { return false; } while ($this->transactionCount > 0) { $this->rollback(); } @$this->mysqli->close(); $this->connected = false; return true; }
function updateCarData($car_id, $number_plate, $color) { $mysqli = new mysqli($GLOBALS["servername"], $GLOBALS["server_username"], $GLOBALS["server_password"], $GLOBALS["database"]); $stmt = $mysqli->prepare("UPDATE car_plates SET number_plate=?, color=? WHERE id=?"); $stmt->bind_param("ssi", $number_plate, $color, $car_id); $stmt->execute(); // tühjendame aadressirea header("Location: table.php"); $stmt->close(); $mysqli->close(); $mysqli->close(); }
function login($mail, $usermdp) { global $varNames, $servname, $user, $mdp, $dbname, $tablename; // inutile //foreach($varNames as $name) // $_SESSION[$name]=html_entity_decode($_SESSION[$name]); $query = "SELECT * FROM " . $tablename . " WHERE " . 'mail="' . $mail . '" AND mdp="' . customHash($usermdp) . '";'; createUserTable(); $mysqli = new mysqli($servname, $user, $mdp, $dbname); if ($mysqli->connect_errno > 0) { die('Unable to connect to database [' . $mysqli->connect_error . ']'); } $resultat = $mysqli->query($query); if ($resultat === false) { echo "Error: query failed. contact your administrator. (Or stop trying hacking database)</br>\n "; //echo $query."</br>\n"; //print_r($mysqli->error_list); return; } /*echo "login debug infos:</br>\n"; echo "login with ".$mail." and ".$usermdp."</br>\n"; echo $query."</br>\n"; echo "Login found with ".($resultat->field_count)." fields, got ".($resultat->num_rows)." rows: ";*/ if ($resultat->num_rows > 1) { echo "Database collision error, ask your administrator.</br>\n"; $mysqli->close(); return false; } if ($resultat->num_rows < 1) { //echo "Mauvais login et/ou mot de passe.</br>\n"; $mysqli->close(); return false; } $ligne = $resultat->fetch_assoc(); //print_r($ligne); $mysqli->close(); if ($ligne == false) { // échec de connection return false; } // mauvais pseudo et/ou mot de passe // Connection réussie $_SESSION["mail"] = $ligne["mail"]; $_SESSION["connu"] = true; $_SESSION["nom"] = $ligne["nom"]; $_SESSION["prenom"] = $ligne["prenom"]; $_SESSION["sexe"] = $ligne["sexe"]; $_SESSION["naissance"] = $ligne["naissance"]; $_SESSION["adresse"] = $ligne["adresse"]; $_SESSION["codepostal"] = $ligne["codepostal"]; $_SESSION["ville"] = $ligne["ville"]; return true; }
function newHomeworkData($homework, $date) { $mysqli = new mysqli($GLOBALS["servername"], $GLOBALS["server_username"], $GLOBALS["server_password"], $GLOBALS["database"]); $stmt = $mysqli->prepare("INSERT INTO homeworks(homework, date, deleted) VALUES(?,?,NULL)"); $stmt->bind_param("ss", $homework, $date); $stmt->execute(); // tühjendame aadressirea header("Location: table.php"); $stmt->close(); $mysqli->close(); $mysqli->close(); }
function updateHomeworkData($homework_id, $homework, $date) { $mysqli = new mysqli($GLOBALS["servername"], $GLOBALS["server_username"], $GLOBALS["server_password"], $GLOBALS["database"]); $stmt = $mysqli->prepare("UPDATE homeworks SET homework=?, date=? WHERE id=?"); $stmt->bind_param("ssi", $homework, $date, $homework_id); $stmt->execute(); // tühjendame aadressirea header("Location: table.php"); $stmt->close(); $mysqli->close(); $mysqli->close(); }
function queryDB($q) { $conn = new mysqli(SERVERNAME, USERNAME, PASSWORD, DATABASE); // Check connection if ($conn->connect_error) { $conn->close(); writeToLog("ERROR_DB", ""); return null; } $result = $conn->query($q); $conn->close(); return $result; }
/** * @see Lumine_Connection_IConnection::close() */ public function close() { $this->dispatchEvent(new Lumine_Events_ConnectionEvent(Lumine_Event::PRE_CLOSE, $this)); if ($this->conn_id && $this->state != self::CLOSED) { Lumine_Log::debug('Liberando resultados todos os resultados'); Lumine_Dialect_Factory::getByName('MySQL')->freeAllResults(); $this->state = self::CLOSED; Lumine_Log::debug('Fechando conexao com ' . $this->getDatabase()); $this->conn->close(); $this->conn = null; } $this->dispatchEvent(new Lumine_Events_ConnectionEvent(Lumine_Event::POS_CLOSE, $this)); }
public function initDb($mysql) { #Initialize the database column, takes mysql server information as a stdClass as argument. $db = new mysqli($mysql->server->address, $mysql->user->id, $mysql->user->pass, $mysql->db, $mysql->server->port); if (!$db) { exit('Database connection problem while initializing birthdate feature : ' . $db->connect_error); } $query = $db->query('ALTER TABLE worker ADD birthdate DATE DEFAULT NULL'); if (!$query) { $err = $db->error; $db->close(); exit("could not create a column 'birthdate' in the table 'worker' : {$err}"); } $db->close(); }
function list_files($dir) { $servername = "localhost"; $username = "******"; $password = "******"; $dbname = "myDB"; try { $conn = new mysqli($servername, $username, $password, $dbname); if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $dizin = opendir($dir); while ($dosya = readdir($dizin)) { if (strpos($dosya, '.') !== FALSE) { if ($dosya != "." && $dosya != "..") { $name = $dir . "/" . $dosya; $sql = "INSERT INTO dizinler (name) VALUES ('" . $name . "')"; if ($conn->query($sql) === TRUE) { echo "OK : " . $name . "</br>"; } else { echo "Error: " . $sql . "<br>" . $conn->error; } } } else { if ($dosya != "." && $dosya != "..") { list_files($dir . "/" . $dosya . ""); } } } $conn->close(); } catch (Exception $e) { echo "Hata :"; } }
/** * Mysqli's binding and returning of statement values * Mysqli requires you to bind variables to the extension in order to * get data out. These values have to be references: * * @see http://php.net/manual/en/mysqli-stmt.bind-result.php * @throws Exception\RuntimeException * @return bool */ protected function loadDataFromMysqliStatement() { $data = null; // build the default reference based bind structure, if it does not already exist if ($this->statementBindValues['keys'] === null) { $this->statementBindValues['keys'] = array(); /* @var $resultResource \mysqli_result */ $resultResource = $this->resource->result_metadata(); foreach ($resultResource->fetch_fields() as $col) { $this->statementBindValues['keys'][] = $col->name; } $this->statementBindValues['values'] = array_fill(0, count($this->statementBindValues['keys']), null); $refs = array(); foreach ($this->statementBindValues['values'] as $i => &$f) { $refs[$i] =& $f; } call_user_func_array(array($this->resource, 'bind_result'), $this->statementBindValues['values']); } if (($r = $this->resource->fetch()) === null) { if (!$this->isBuffered) { $this->resource->close(); } return false; } elseif ($r === false) { throw new Exception\RuntimeException($this->resource->error); } // dereference for ($i = 0, $count = count($this->statementBindValues['keys']); $i < $count; $i++) { $this->currentData[$this->statementBindValues['keys'][$i]] = $this->statementBindValues['values'][$i]; } $this->currentComplete = true; $this->nextComplete = true; $this->position++; return true; }