当前位置: 首页>>代码示例>>PHP>>正文


PHP connectDatabase函数代码示例

本文整理汇总了PHP中connectDatabase函数的典型用法代码示例。如果您正苦于以下问题:PHP connectDatabase函数的具体用法?PHP connectDatabase怎么用?PHP connectDatabase使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了connectDatabase函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: deleteGroup

    function deleteGroup($id) {
        $database = connectDatabase();

        if ($database == false) {
			return "<p>Nie udało się połączyć z bazą danych. Spróbuj później.</p>";
		}

        @ $result = $database->query("select id 
									  from groups
									  where id='$id'");
        
        if ($result == false) {
			return "<p>Nie udało się wykonać zapytania. Spróbuj później.</p>";
		}

        if (!$result->num_rows) {
			return "<p>Grupa o podanym id nie istnieje.</p>";
		}

        @ $result = $database->query("delete 
									  from groups
									  where id='$id'");
        
        if ($result == false) {
			return "<p>Nie udało się wykonać zapytania. Spróbuj później.</p>";
		}

        return "<p>Grupa została poprawnie usunięta</p>";
    }
开发者ID:nirme,项目名称:dominatrix2000,代码行数:29,代码来源:deletegroup.php

示例2: addGroup

	function addGroup($group) {
		// wywołanie funkcji łączącej się z bazą
		$database = connectDatabase();
		
		// zwrócenie błędu jeśli nie dostano zasobu bazy
		if ($database == false) {
			return "<p>Nie udało się połączyć z bazą danych. Spróbuj później.</p>";
		}

		@ $result = $database->query("select name 
									  from groups
									  where name='$group'");

		if ($result == false) {
			return "<p>Nie udało się wykonać zapytania. Spróbuj później.</p>";
		}

		if ($result->num_rows > 0) {
			return "<p>Grupa o takiej nazwie już istnieje.</p>";
		}

	   	// zapytanie bazy danych o użytkownika
		@ $result = $database->query("insert into groups (name) values ('$group')");
									  
		// jeśli nie udało się wykonać zapytania
		if ($result == false) {
			return "<p>Nie udało się wykonać zapytania. Spróbuj później.</p>";
		} else {
			return "<p>Grupa została dodana</p>";
		}
		$database->close();
	}
开发者ID:nirme,项目名称:dominatrix2000,代码行数:32,代码来源:addgroup.php

示例3: setLogin

	function setLogin($login) {
        $database = connectDatabase();
        $indeks = $_SESSION['userIndeks'];
                
        // zwrócenie błędu jeśli nie dostano zasobu bazy
		if ($database == false) {
			return "<p>Nie udało się połączyć z bazą danych. Spróbuj później.</p>";
		}

		@ $result = $database->query("select * 
									  from users
									  where login = '$login'");
		// jeśli nie udało się wykonać zapytania
		if ($result == false) {
			return "<p>Nie udało się wykonać zapytania. Spróbuj później.</p>";
		}
		
		// jeśli nie otrzymano żadnego rezultatu
		if ($result->num_rows > 0) {
			return "<p>Podany login jest już zarejestrowany. Musisz wybrać inny.</p>";
		}		

        @ $result = $database->query("update users
									  set login = '$login'
									  where indeks = '$indeks'");
		// jeśli nie udało się wykonać zapytania
		if ($result == false) {
			return "<p>Nie udało się wykonać zapytania. Spróbuj później.</p>";
		} else {
            $_SESSION['userLogin'] = $login;
			return "<p>Login został ustawiony poprawnie.</p>";

		}

    }
开发者ID:nirme,项目名称:dominatrix2000,代码行数:35,代码来源:setlogin.php

示例4: login

 /**
  * @param $login_form
  * @return false | User ログイン失敗時にfalseを返し、成功の場合はUserを返す。
  */
 public function login($login_form)
 {
     $dbh = connectDatabase();
     $sql = "select * from users where name = :name and email = :email";
     $stmt = $dbh->prepare($sql);
     $stmt->bindParam(":name", $login_form['name']);
     $stmt->bindParam(":email", $login_form['email']);
     $stmt->execute();
     $stmt->setFetchMode(PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE, 'User', array('id', 'name', 'email', 'image_type', 'image', 'created_at', 'login_count'));
     return $stmt->fetch();
 }
开发者ID:ogontaro,项目名称:elites-output,代码行数:15,代码来源:user_mapper.php

示例5: registerFormSubmitted

function registerFormSubmitted()
{
    require 'include/configGlobals.php';
    connectDatabase();
    slashAllInputs();
    //This makes sure they did not leave any fields blank
    if (!$_POST['username'] | !$_POST['email'] | !$_POST['firstName'] | !$_POST['lastName']) {
        die('You did not complete all of the required fields');
    }
    if (!isUsernameValid($_POST['username'])) {
        die('Sorry, that username is invalid. Please go back and try again.');
    }
    // checks if the username is in use
    $usercheck = $_POST['username'];
    $check = mysql_query("SELECT username FROM users WHERE username = '{$usercheck}'") or die(mysql_error());
    $check2 = mysql_num_rows($check);
    //if the name exists it gives an error
    if ($check2 != 0) {
        die('Sorry, the username ' . $_POST['username'] . ' is already in use. Please go back and try again.');
    }
    $emailcheck = $_POST['email'];
    $check = mysql_query("SELECT email FROM users WHERE email = '{$emailcheck}'") or die(mysql_error());
    $check2 = mysql_num_rows($check);
    //if the email exists it gives an error
    if ($check2 != 0) {
        die('Sorry, the email ' . $_POST['email'] . ' has already been registered. Please go back and try again.');
    }
    $tempPassword = rand_string(16);
    // here we encrypt the password and add slashes if needed
    $hashPassword = md5($tempPassword);
    $hashUsername = md5($_POST['username']);
    $hash256Password = bin2hex(mhash(MHASH_SHA256, $tempPassword));
    $hash256Username = bin2hex(mhash(MHASH_SHA256, $_POST['username']));
    $creationDate = date('Y-m-d');
    // now we insert it into the database
    $insert = "INSERT INTO users (username, pass, sha256_user, sha256_pass, fname, lname, addr1, addr2, city, state, zip, hphone, cphone, email, econtact, econtact_phone, econtact_rel, creation) VALUES (\n           '" . $_POST['username'] . "',\n           '" . $hashPassword . "',\n\t\t   '" . $hash256Username . "',\n\t\t   '" . $hash256Password . "',\n           '" . $_POST['firstName'] . "',\n           '" . $_POST['lastName'] . "',\n           '" . $_POST['address1'] . "',\n           '" . $_POST['address2'] . "',\n           '" . $_POST['city'] . "',\n           '" . $_POST['state'] . "',\n           '" . $_POST['zipCode'] . "',\n           '" . $_POST['homePhone'] . "',\n           '" . $_POST['cellPhone'] . "',\n           '" . $_POST['email'] . "',\n           '" . $_POST['econtact'] . "',\n           '" . $_POST['econtactPhone'] . "',\n           '" . $_POST['econtactRel'] . "',\n           '" . $creationDate . "'\n           )";
    $add_member = mysql_query($insert);
    $to = $_POST['email'];
    $from = $email_Administrator;
    $subject = 'Registered on ' . $club_Abbr . ' Online Registration Site';
    $message = "--{$mime_boundary}\n";
    $message .= "Content-Type: text/plain; charset=UTF-8\r\n";
    $message .= "Content-Transfer-Encoding: 8bit\r\n";
    $message .= 'Thank you for registering on the ' . $club_Abbr . ' Online Registration site.' . "\n" . "\n" . 'Your username is: [ ' . $usercheck . " ]\n" . 'Your temporary password is: [ ' . $tempPassword . " ]\n" . "\n" . 'Login at ' . $http_Logout . ' to change your password and register for events.' . "\n" . "\n" . 'Thank you!' . "\n" . '- ' . $club_Abbr . ' Administration' . "\n";
    $message .= "--{$mime_boundary}--\n\n";
    if (sendEmail($to, $from, $subject, $message) != false) {
        echo "<h1>Registered</h1>\n";
        echo "Thank you, you have registered. An email has been sent to " . $to . " \n";
        echo "with your username and temporary password. Depending on internal server traffic, this may take some time.<br><br>\n";
        echo "When you receive your temporary password you may <a href=\"index.php\">login</a> to continue.\n";
    } else {
        echo "<h1>Internal Email Error. Please contact administrator at " . $email_Administrator . "</h1>\n";
    }
}
开发者ID:sarahbx,项目名称:moers,代码行数:54,代码来源:register.php

示例6: is_registered

/**
 * すでに登録されているユーザネームか判定する
 * @param $name 判定対象のユーザネーム
 * @return bool 登録されているユーザネームの場合、trueを返す
 */
function is_registered($name)
{
    $dbh = connectDatabase();
    $sql = "SELECT name FROM users WHERE name = :name";
    $stmt = $dbh->prepare($sql);
    $stmt->bindParam(':name', $name);
    $stmt->execute();
    if ($stmt->fetch()) {
        return true;
    } else {
        return false;
    }
}
开发者ID:ogontaro,项目名称:elites-output,代码行数:18,代码来源:functions.php

示例7: changePassword

function changePassword($email, $pass)
{
    $hash = hashPassword($pass);
    $con = connectDatabase();
    while (1) {
        $stmt = $con->prepare("CALL changePassword(?,?)");
        $stmt->bind_param("ss", $email, $hash);
        $stmt->execute();
        $stmt->close();
        break;
    }
    $con->close();
}
开发者ID:tipsycoder,项目名称:familytree_php,代码行数:13,代码来源:superservice.php

示例8: updateUserField

function updateUserField($email, $value, $procName, &$errMsg = "")
{
    $returnVal = true;
    $conn = connectDatabase();
    $stmt = $conn->prepare("Call {$procName}(?,?)");
    $stmt->bind_param("ss", $email, $value);
    $stmt->execute();
    if ($stmt->errno !== 0) {
        $returnVal = false;
    }
    $errMsg = $stmt->error;
    $stmt->close();
    closeDatabase($conn);
    return $returnVal;
}
开发者ID:tipsycoder,项目名称:familytree_php,代码行数:15,代码来源:userservice.php

示例9: forgotFormSubmitted

function forgotFormSubmitted()
{
    require 'include/configGlobals.php';
    // Connects to your Database
    connectDatabase();
    slashAllInputs();
    //This makes sure they did not leave any fields blank
    if (!$_POST['email']) {
        die('You did not complete all of the required fields');
    }
    // checks if the email is in use
    $emailcheck = $_POST['email'];
    $check = mysql_query("SELECT username FROM users WHERE email = '{$emailcheck}'") or die(mysql_error());
    $check2 = mysql_num_rows($check);
    //if the email doesn't exists it gives an error
    if ($check2 == 0) {
        die('Sorry, no user with email ' . $emailcheck . ' is registered in the database. Please try again.');
    }
    while ($info = mysql_fetch_array($check)) {
        $usercheck = $info['username'];
    }
    $tempPassword = rand_string(16);
    // here we encrypt the password
    $sha256_pass = bin2hex(mhash(MHASH_SHA256, $tempPassword));
    // now we insert it into the database
    $update_member = mysql_query("UPDATE users SET sha256_pass='{$sha256_pass}' WHERE username='{$usercheck}'");
    $sha256_pass = rand_string(128);
    // clear md5 hash
    $update_member = mysql_query("UPDATE users SET pass='' WHERE username='{$usercheck}'");
    $to = $emailcheck;
    $from = $email_Administrator;
    $subject = 'Reset Info for ' . $club_Abbr . ' Online Registration Site';
    $message = "--{$mime_boundary}\n";
    $message .= "Content-Type: text/plain; charset=UTF-8\r\n";
    $message .= "Content-Transfer-Encoding: 8bit\r\n";
    $message .= 'Your password has been reset on the ' . $club_Abbr . ' Online Registration site at your request.' . "\n" . "\n" . 'Your username is: [ ' . $usercheck . " ]\n" . 'Your temporary password is: [ ' . $tempPassword . " ]\n" . "\n" . 'Login at ' . $http_Logout . ' to change your password and register for events.' . "\n" . "\n" . 'Thank you!' . "\n" . '- ' . $club_Abbr . ' Administration' . "\n";
    $message .= "--{$mime_boundary}--\n\n";
    sendEmail($to, $from, $subject, $message);
    $tempPassword = rand_string(16);
    // clear variable data
    echoMainHeader();
    echo "<h1>Email Sent.</h1>\n";
    echo "Thank you, you have registered. An email has been sent to " . $_POST['email'] . " \n";
    echo "with your username and temporary password. Depending on internal server traffic, this may take some time.<br><br>\n";
    echo "When you receive your temporary password you may <a href=\"" . $http_Logout . "\">login</a> to continue.\n";
    echoMainFooter();
}
开发者ID:sarahbx,项目名称:moers,代码行数:47,代码来源:forgot.php

示例10: logoutUser

function logoutUser()
{
    header("Content-Type: text/html; charset=utf-8");
    logLogout(getCookie('ID'));
    if (getCookie('ID')) {
        connectDatabase();
        slashArray($_COOKIE);
        // reset session id
        $sessionId = rand_string(32);
        $update = "UPDATE users SET session_id='{$sessionId}' WHERE sha256_user='" . getCookie('ID') . "'";
        $result = mysql_query($update);
        $sessionId = rand_string(32);
    }
    //this deletes the cookies
    clearCookies();
    header("Location: index.php");
}
开发者ID:sarahbx,项目名称:moers,代码行数:17,代码来源:logout.php

示例11: getAllRelations

function getAllRelations()
{
    $conn = connectDatabase();
    $pEmail = "";
    $cEmail = "";
    $resultArray = [];
    $resultArray['pEmails'] = [];
    $resultArray['cEmails'] = [];
    $stmt = $conn->prepare("CALL getRelations()");
    $stmt->execute();
    $stmt->bind_result($pEmail, $cEmail);
    while ($stmt->fetch()) {
        array_push($resultArray['pEmails'], $pEmail);
        array_push($resultArray['cEmails'], $cEmail);
    }
    return $resultArray;
}
开发者ID:tipsycoder,项目名称:familytree_php,代码行数:17,代码来源:super_data.php

示例12: iduResults

function iduResults($statement)
{
    $output = "";
    $outputArray = array();
    $db = connectDatabase();
    if ($db) {
        $result = mysql_query($statement);
        if (!$result) {
            $output .= "ERROR";
            $output .= "<br /><font color=red>MySQL No: " . mysql_errno();
            $output .= "<br />MySQL Error: " . mysql_error();
            $output .= "<br />SQL Statement: " . $statement;
            $output .= "<br />MySQL Affected Rows: " . mysql_affected_rows() . "</font><br />";
        } else {
            $output = mysql_affected_rows();
        }
    } else {
        $output = 'ERROR-No DB Connection';
    }
    return $output;
}
开发者ID:Edwards9489,项目名称:estatge-agent-system,代码行数:21,代码来源:MSc_Properties+-+Common_Functions.php

示例13: changePassword

	function changePassword($oldPassword, $newPassword) {
		// wywołanie funkcji łączącej się z bazą
		$database = connectDatabase();
		$email = $_SESSION['userMail'];
		
		// zwrócenie błędu jeśli nie dostano zasobu bazy
		if ($database == false) {
			return "<p>Nie udało się połączyć z bazą danych. Spróbuj później.</p>";
		}
		
		@ $result = $database->query("select mail 
									  from users
									  where pass = sha1('$oldPassword')");
									  
		// jeśli nie udało się wykonać zapytania
		if ($result == false) {
			return "<p>Nie udało się wykonać zapytania. Spróbuj później.</p>";
		}
		
		// jeśli nie otrzymano żadnego rezultatu
		if ($result->num_rows == 0) {
			return "<p>Podane hasło jest błędne.</p>";
		}							 
		
		// zapytanie bazy danych o użytkownika
		@ $result = $database->query("update users
									  set pass = sha1('$newPassword')
									  where mail = '$email'
									  and pass=sha1('$oldPassword')");
									  
		// jeśli nie udało się wykonać zapytania
		if ($result == false) {
			return "<p>Nie udało się wykonać zapytania. Spróbuj później.</p>";
		} else {
			return "<p>Hasło zostało poprawnie zmienione.</p>";
		}

		$database->close();
	}
开发者ID:nirme,项目名称:dominatrix2000,代码行数:39,代码来源:changepassword.php

示例14: insertComment

function insertComment()
{
    session_start();
    $story_id = $_SESSION['story_id'];
    $comment_to = htmlspecialchars($_POST["replyCommentTo"]);
    $comment_creator = $_SESSION['user_name'];
    $comment_content = htmlspecialchars($_POST["commentContent"]);
    $connectComment = connectDatabase();
    $insertComment = $connectComment->prepare("insert into comment (story_id,comment_creator,comment_to,comment_content) values ( ?, ?, ?, ?)");
    if (!$insertComment) {
        printf("insert failed: %s\n", $connectComment->connect_errno);
    }
    $insertComment->bind_param('isss', $story_id, $comment_creator, $comment_to, $comment_content);
    $insertComment->execute();
    $insertComment->close;
    ///////new message
    $comment_id;
    $connect = connectDatabase();
    $queryComment = $connect->prepare("select id from comment order by comment_time DESC LIMIT 1");
    if (!$queryComment) {
        printf("query failed: %s\n", $connect->connect_errno);
    }
    $queryComment->execute();
    $queryComment->bind_result($commentId);
    if ($queryComment->fetch()) {
        $comment_id = $commentId;
    }
    $queryComment->close;
    //////insert new message
    $user_id = $_POST["user_name"];
    $connectUnread = connectDatabase();
    $insertUnread = $connectUnread->prepare("insert into unread_comment (user_id,comment_id) values (?, ?)");
    if (!$insertUnread) {
        printf("insert failed: %s\n", $connectUnread->connect_errno);
    }
    $insertUnread->bind_param('si', $comment_to, $comment_id);
    $insertUnread->execute();
    $insertUnread->close;
}
开发者ID:BojianLi,项目名称:News-Website,代码行数:39,代码来源:submit_comment.php

示例15: session_start

<?php

session_start();
include '../functions.php';
$connect = connectDatabase();
//Getting form elements
if (isset($_SESSION['currentCity'])) {
    if (isset($_SESSION['userId'])) {
        $city = $_SESSION['currentCity'];
        // $movie = $_SESSION['movie'];
        $theatre = $_SESSION['theatre'];
        $numberOfTickets = $_POST['ticketsCount'];
        $showId = $_POST['selectedShow'];
        $userId = $_SESSION['userId'];
        //Procedure call to DB
        $query = "CALL insertBookings(?, ?, ?, @booking_id)";
        $stmt = $connect->prepare($query);
        $stmt->bind_param('iii', $userId, $showId, $numberOfTickets);
        $stmt->execute();
        $result = $stmt->get_result();
        $select = $connect->query('SELECT @booking_id');
        $fetched = $select->fetch_assoc();
        $id = $fetched['@booking_id'];
        header("Location: ../bookinStatus.php");
        exit;
    } else {
        $_SESSION['loginAlert'] = "Please login to book tickets";
        header("Location: ../book.php");
        exit;
    }
}
开发者ID:NiranjanRavichandran,项目名称:DB-Project,代码行数:31,代码来源:bookingScript.php


注:本文中的connectDatabase函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。