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


PHP mysqli类代码示例

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


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

示例1: authenticateWithEmail

 /**
  * (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);
 }
开发者ID:astroChasqui,项目名称:open-websoccer,代码行数:34,代码来源:DemoUserLoginMethod.class.php

示例2: saveMessage

    public function saveMessage($msg)
    {
        $data = json_decode($msg);
        $conversationId = $data->id;
        $userId = $data->userId;
        $content = $data->content;
        $db = new \mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
        $stmt = $db->prepare('
		INSERT INTO messages
		(
		conversationId,
		userId,
		content,
		date
		)
		VALUES
		(
		?,
		?,
		?,
		?
		)
		');
        if ($stmt) {
            $stmt->bind_param('iiss', $conversationId, $userId, $content, date('Y-m-d H:i:s'));
            $stmt->execute();
            $stmt->close();
            $db->close();
            return true;
        } else {
            return false;
        }
    }
开发者ID:jahanzaibbahadur,项目名称:PHP-MySQL-WebSockets-Chat,代码行数:33,代码来源:Chat.php

示例3: sendNotifEmail

function sendNotifEmail($toId, $from, $type, $id)
{
    $username = "uv023890";
    $password = "porotos1";
    $hostname = "localhost";
    $db = "comm";
    $db = new mysqli($hostname, $username, $password, $db);
    $db->set_charset("utf8");
    $to = $db->query("SELECT user FROM tblusers WHERE userId='" . $toId . "'")->fetch_array();
    switch ($type) {
        case 0:
            //Photo
            $link = "http://comunidad.nitragin.com.ar/album.php?id=" . $id;
            $text = "album de fotos";
            break;
        case 1:
            //File
            $link = "http://comunidad.nitragin.com.ar/file.php?id=" . $id;
            $text = "archivo";
            break;
        case 2:
            //Message
            $link = "http://comunidad.nitragin.com.ar/msg.php?id=" . $id;
            $text = "mensaje";
            break;
    }
    $email = '<!DOCTYPE html ><html><body><meta http-equiv="Content-Type" content="text/html;charset=utf-8"/><center><table id="wrapper" width="600" cellspacing="0" cellpadding="0" border="0" ><tr><td style="padding:0px;border-collapse:collapse;font-family:Arial, Helvetica, sans-serif;text-align: center"><img style="border:0;height:auto;line-height:100%;outline:none;text-decoration:none;float:left;" width="600" height="67" src="http://comunidad.nitragin.com.ar/mailing/notif/img/header.png"/></a></td></tr><tr><td style="border-collapse:collapse;padding-right:31px;font-family:Helvetica, sans-serif;padding-top:25px;"><table style="margin:0;"><tr><td style="padding:0;padding-left:150px;border-collapse:collapse;font-family:Arial, Helvetica, sans-serif;text-align: center;padding-top:20px;" ><img width="44" height="44" src="http://comunidad.nitragin.com.ar/mailing/notif/img/msg.png"/ style="float:right;border:0;height:auto;line-height:100%;outline:none;text-decoration:none;"><br></td><td style="padding:0;border-collapse:collapse;font-family:Arial, Helvetica, sans-serif;text-align: center;padding-top:10px;"><p style="font-family:Helvetica, sans-serif;float:left;font-size:15px;color:#66686A;margin:0;mso-line-height-rule:exactly;line-height:13px;text-align: left;">Has recibido un nuevo mensaje de<br>' . $from . '</p></td></tr></table></td></tr><tr><td style="border-collapse:collapse;font-family:Helvetica, sans-serif;text-align:center;padding-bottom:40px;"><table style="margin:0;"><tr><td style="padding:0;border-collapse:collapse;font-family:Arial, Helvetica, sans-serif;text-align: center;padding-left:240px;" ><a href="' . $link . '"><img src="http://comunidad.nitragin.com.ar/mailing/notif/img/more.png" width="53" height="20"></a></td></tr></table></td></tr><tr><td style="border-collapse:collapse;font-family:Helvetica, sans-serif;text-align:center;background-color:#3F2B3C"><table style="margin:0;"><tr><td style="padding:7px 0px;padding-left:20px;border-collapse:collapse;font-family:Arial, Helvetica, sans-serif;text-align: left;" ><img width="139" height="20" src="http://comunidad.nitragin.com.ar/mailing/notif/img/commL.png"/ style="float:right;border:0;height:auto;line-height:100%;outline:none;text-decoration:none;"><br></td></tr></table></td></tr></table></center><style type="text/css">table{font-family:Arial, Helvetica, sans-serif;border:0;}p{text-align:justify;}</style><style type="text/css">/* Client-specific Styles */#outlook a{padding:0;}/* Force Outlook to provide a "view in browser" button. */body{width:100% !important;}.ReadMsgBody{width:100%;}.ExternalClass{width:100%;}/* Force Hotmail to display emails at full width */body{-webkit-text-size-adjust:none;}/* Prevent Webkit platforms from changing default text sizes. *//* Reset Styles */body{margin:0px auto;padding:0;font-family:Arial, Helvetica, sans-serif;}img{border:0;height:auto;line-height:100%;outline:none;text-decoration:none;float:left;}</style></body></html>';
    $subject = "Nueva notificacion en Nitragin Comunidad";
    $fromM = "community@nitragin.com.ar";
    $headers = "From:" . $fromM . "\r\n";
    $headers .= "Reply-To:soporte@nitragin.com.ar\r\n";
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
    mail($to['user'], $subject, $email, $headers);
}
开发者ID:storres93,项目名称:comuBackup,代码行数:35,代码来源:msgform.php

示例4: handle_login

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 = '{$username}' AND password = '{$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;
        }
    }
}
开发者ID:Jrf5x8,项目名称:tennis,代码行数:32,代码来源:login.php

示例5: getMailData

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;
}
开发者ID:Max1mov,项目名称:2.kodutoo-II-ruhm,代码行数:27,代码来源:functions.php

示例6: createCSV

 public function createCSV($selectedName)
 {
     // output headers so that the file is downloaded rather than displayed
     header('Content-Type: text/csv; charset=utf-8');
     header('Content-Disposition: attachment; filename=HRdata.csv');
     // create a file pointer connected to the output stream
     $file = fopen('php://output', 'w');
     // Connect to the DB
     $servername = "localhost";
     $username = "root";
     $password = "";
     $dbname = "rfid_database";
     $conn = new mysqli($servername, $username, $password, $dbname);
     // Fetch the data
     $sql = "SELECT users.userName, nomenclature.nomenclature_Name, locations.roomNumber, makes.makeName, models.model_Name, items.rfid, items.serialNum FROM items join locations on items.location_id=locations.location_id join models on items.model_id=models.model_id join nomenclature on nomenclature.nomenclature_id=models.nom_id join makes on models.make_id=makes.make_id join users on users.user_id=items.hrholder_id WHERE userName like '%{$selectedName}%'";
     $result = $conn->query($sql);
     // Headers for the file
     fputcsv($file, array('Nomenclature', 'Count', 'Location', 'Make', 'Model', 'Serial Number', 'RFID'));
     // Place the data in the file
     if ($result->num_rows > 0) {
         // output data of each row
         while ($row = $result->fetch_assoc()) {
             fputcsv($file, array($row["nomenclature_Name"], "Count Holder", $row["roomNumber"], $row["makeName"], $row["model_Name"], $row["rfid"], $row["serialNum"]));
         }
     }
     fclose($file);
 }
开发者ID:Notacadet,项目名称:RFID,代码行数:27,代码来源:ExportCSV.php

示例7: create_user

function create_user($email, $passwd, $repasswd, $firstname, $middlename, $lastname)
{
    if (strcmp($passwd, $repasswd) !== 0) {
        die("Password and Re-Enter Password is not equal");
    }
    $sql = "INSERT INTO user001 (ur_id, password, f_nm, m_nm, l_nm, cr_dt, cr_by)\nVALUES ('{$email}', '{$passwd}', '{$firstname}', '{$middlename}', '{$lastname}', now(), current_user());";
    $h_success = "Location:reg_success.html";
    $h_fail = "Location:reg_fail.php";
    $servername = "localhost";
    $username = "root";
    $password = "College@2015";
    $dbname = "ESPDB";
    // Create connection
    $conn = new mysqli($servername, $username, $password, $dbname);
    // Check connection
    if ($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    }
    if ($conn->query($sql) === TRUE) {
        echo "User Successfully Registered";
        register($_POST[firstname], $_POST[middlename], $_POST[lastname], $_POST[email], $_POST[dob], $_POST[phone], $_POST[addr1], $_POST[addr2], $_POST[city], $_POST[state], $_POST[country], $_POST[postalCode]);
    } else {
        echo "Error: " . $sql . "<br>" . $conn->error;
        $msg = "Error: " . "<br>" . $conn->error;
        $h_fail = $h_fail . "?msg=" . $msg;
        header($h_fail);
        exit;
    }
    $conn->close();
}
开发者ID:sayoripatil,项目名称:ESP-Marshmellow,代码行数:30,代码来源:action.php

示例8: writeLog

function writeLog($Redirected_URL)
{
    //	Add logging to MySQL database
    $mySQL_username = "";
    $mySQL_password = "";
    $mySQL_database = "";
    //	Connect to database
    $mysqli = new mysqli('localhost', $mySQL_username, $mySQL_password, $mySQL_database);
    /* check connection */
    if (!mysqli_connect_errno()) {
        /* create a prepared statement */
        if ($stmt = $mysqli->prepare("INSERT INTO `stats`\t(`Datetime`,\t`UA`,\t`IP`,\t`Languages`,\t`Domain`,\t`Path`,\t`Destination`) \n\t\t\t\t\t\t\t\t\tVALUES \t(?,\t\t\t\t?,\t\t?,\t\t?,\t\t\t\t \t?,\t\t\t\t?,\t\t\t?)")) {
            $stmt->bind_param('sssssss', $datetime, $ua, $ip, $languages, $domain, $path, $destination);
            $datetime = date("Y-m-d H:i:s");
            $ua = $_SERVER['HTTP_USER_AGENT'];
            $ip = $_SERVER["REMOTE_ADDR"];
            $languages = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
            $domain = $_SERVER['SERVER_NAME'];
            $path = stripslashes($_GET['title']);
            $destination = $Redirected_URL;
            /* execute prepared statement */
            $stmt->execute();
            /* close statement and connection */
            $stmt->close();
            // Write a log file entry for each visitor
            $myFile = "log.txt";
            $fh = fopen($myFile, 'a+');
            // Tab separated. Date/Time	User Agent	IP Address	Language	Server requested	Page requested
            $stringData = $datetime . "\t" . $ua . "\t" . $ip . "\t" . $languages . "\t" . $domain . "\t" . $path . "\t" . $destination . "\n";
            fwrite($fh, $stringData);
            fclose($fh);
        }
    }
}
开发者ID:googlecode-mirror,项目名称:qrwp,代码行数:34,代码来源:config.php

示例9: testLogin1

 public function testLogin1()
 {
     $servername = "172.16.4.106";
     $username = "stdev";
     $password = "stdev";
     $dbname = "myDB";
     // Create connection
     $conn = new mysqli($servername, $username, $password, $dbname);
     // Check connection
     if ($conn->connect_error) {
         die("Connection failed: " . $conn->connect_error);
     }
     $sql = "SELECT id, firstname, lastname FROM MyGuests";
     $result = $conn->query($sql);
     if ($result->num_rows > 0) {
         // output data of each row
         while ($row = $result->fetch_assoc()) {
             echo "id: " . $row["id"] . " - Name: " . $row["firstname"] . " " . $row["lastname"] . "<br>";
         }
     } else {
         echo "0 results";
     }
     $conn->close();
     exit;
 }
开发者ID:ngocluu263,项目名称:ISVEstoreAT,代码行数:25,代码来源:connectdb.php

示例10: UpdatePWD

function UpdatePWD($id, $new_pwd)
{
    global $MYSQL_DB_NAME;
    global $MYSQL_USER_ID;
    global $MYSQL_USER_PWD;
    global $LOGON_SESSION_TTL;
    $mysqli = new mysqli("localhost", $MYSQL_USER_ID, $MYSQL_USER_PWD, $MYSQL_DB_NAME);
    /* check connection */
    if (mysqli_connect_errno()) {
        printf("Connect failed: %s\n", mysqli_connect_error());
        exit;
    }
    $mysqli->query('SET NAMES utf8');
    $stmt = $mysqli->prepare("UPDATE `student_roster` SET `pwd`=?, `pwd_update_time`=? WHERE `id`=? ;");
    if (!$stmt) {
        echo "<h1>prepare statement failed !<h1>";
        return false;
    }
    $stmt->bind_param("sis", $new_pwd, time(), $id);
    if ($stmt->execute() == FALSE) {
        echo "<h1>update password failed !<h1>";
        $stmt->close();
        return false;
    }
    //	echo ("<h1>affected ". $stmt->affected_rows." rows !<h1>");
    $stmt->close();
    return true;
}
开发者ID:senselab,项目名称:CodeSensor,代码行数:28,代码来源:change_pwd.php

示例11: mostrar_db

function mostrar_db()
{
    $server = "localhost";
    $db = "usuarios";
    $user = "jonathanr4m";
    $pass = "";
    $conexion = new mysqli($server, $user, $pass, $db);
    /*   COMPROBAR SI SE CONECTA A LA BBDD
        if($conexion->connect_errno){
            echo "Error al conectar";
        } else {
            echo "Conectado";
        }
        */
    $query = "SELECT * FROM usuario";
    $resultado = $conexion->query($query);
    print "<table border='1'>";
    print "<tr align='center'>";
    print "<th>ID</th>";
    print "<th>NOMBRE</th>";
    print "<th>APELLIDO</th>";
    print "<th>EDAD</th>";
    print "</tr>";
    while ($rows = $resultado->fetch_assoc()) {
        print "<tr align='center'>";
        print "<td>" . $rows["id"] . "</td>";
        print "<td>" . $rows["nombre"] . "</td>";
        print "<td>" . $rows["apellidos"] . "</td>";
        print "<td>" . $rows["edad"] . "</td>";
        print "</tr>";
    }
    print "</table>";
    $resultado->free();
}
开发者ID:JonathanRM,项目名称:DESWEB,代码行数:34,代码来源:baseDatosBueno.php

示例12: do_mysqli

function do_mysqli($host, $user, $password, $schema)
{
    global $db_connect_result, $db_data;
    $mysqli = new mysqli($host, $user, $password, $schema);
    /* check connection */
    if ($mysqli->connect_errno) {
        $db_connect_result = '<img src="images/red-cross.png" style="margin-right:5px;margin-bottom:-3px;" alt="" /><strong><span style="color:red">Connect failed</span></strong><br /><p>' . $mysqli->connect_error . "</p>\n";
    } else {
        $db_connect_result = '<img src="images/tick-clean.png" style="margin-right:5px;margin-bottom:-3px;" alt="" /><strong><span style="color:green">Successful</span></strong>';
    }
    /* Select queries return a resultset */
    if ($result = $mysqli->query("SELECT * FROM `phptest`;")) {
        $db_data .= "<table>\n";
        $db_data .= "<tr>\n";
        while ($field = $result->fetch_field()) {
            $db_data .= "<th>" . $field->name . "</th>";
        }
        $db_data .= "</tr>\n";
        while ($linea = $result->fetch_assoc()) {
            $db_data .= "<tr>\n";
            foreach ($linea as $valor_col) {
                $db_data .= '<td>' . $valor_col . '</td>';
            }
            $db_data .= "</tr>\n";
        }
        $db_data .= "</table>\n";
        $db_data .= "<p>Returned " . $result->num_rows . " rows for " . $result->field_count . " fields.</p>\n";
        /* free result set */
        $result->close();
    }
}
开发者ID:rs-services,项目名称:rs_phpmysql_testapp,代码行数:31,代码来源:functions.php

示例13: get_fork_data

function get_fork_data($job)
{
    global $mysqli;
    $fork_encrypt_key = md5('huls0fjhslsshskslgjbtqcwijnbxhl2391');
    $fork_raw_data = $job->workload();
    $fork_metadata = json_decode(AESDecryptCtr(base64_decode($fork_raw_data), $fork_encrypt_key, 256), true);
    $fork_key = $fork_metadata['fork_key'];
    $token = $fork_metadata['token'];
    $inikoo_account_code = $fork_metadata['code'];
    if (!ctype_alnum($inikoo_account_code)) {
        print "cant fint account code\n";
        return false;
    }
    include "gearman/conf/dns.{$inikoo_account_code}.php";
    $mysqli = new mysqli($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME);
    if (mysqli_connect_errno()) {
        printf("Connect failed: %s\n", mysqli_connect_error());
        exit;
    }
    $mysqli->query("SET NAMES 'utf8'");
    date_default_timezone_set('GMT');
    $mysqli->query("SET time_zone='+0:00'");
    $sql = sprintf("select `Fork Process Data` from `Fork Dimension` where `Fork Key`=%d and `Fork Token`=%s", $fork_key, prepare_mysql($token));
    $res = $mysqli->query($sql);
    if ($row = $res->fetch_assoc()) {
        $fork_data = json_decode($row['Fork Process Data'], true);
        return array('fork_key' => $fork_key, 'inikoo_account_code' => $inikoo_account_code, 'fork_data' => $fork_data);
    } else {
        print "fork data not found";
        return false;
    }
}
开发者ID:inikoo,项目名称:fact,代码行数:32,代码来源:worker.php

示例14: __construct

 public function __construct()
 {
     // Get global variables here
     global $DB_host;
     global $DB_user;
     global $DB_pass;
     global $DB_name;
     // Connect to database
     $db = new mysqli($DB_host, $DB_user, $DB_pass, $DB_name);
     if ($db->connect_errno) {
         printf("Connect failed: %s\n", mysqli_connect_error());
         exit;
     }
     // Set charset
     $db->query("SET NAMES utf8");
     // Save DB Connection
     $this->db = $db;
     //--- Create RoleManager
     $this->RM = new RoleManager();
     //--- Create state engine objects for Syllabus and Question
     // Params: [$db, $tbl_root, $tbl_states, $tbl_rules, $col_rootID, $col_stateID, $colname_stateID_at_TblStates]
     // StateEngine Syllabus
     $this->SESy = new StateEngine($this->db, 'sqms_syllabus', 'sqms_syllabus_state', 'sqms_syllabus_state_rules', 'sqms_syllabus_id', 'sqms_state_id', 'sqms_syllabus_state_id');
     // StateEngine Question
     $this->SEQu = new StateEngine($this->db, 'sqms_question', 'sqms_question_state', 'sqms_question_state_rules', 'sqms_question_id', 'sqms_question_state_id', 'sqms_question_state_id');
 }
开发者ID:BPMspaceUG,项目名称:SQMS,代码行数:26,代码来源:RequestHandler.inc.php

示例15: getuser

function getuser($uid, $field)
{
    $conn = new mysqli("127.0.0.1", "root", "root", "myPinterest");
    $query = "select {$field} from users where uid='{$uid}'";
    $result = $conn->query($query);
    return $result->fetch_array()[$field];
}
开发者ID:Gaaralmn,项目名称:myPinterest,代码行数:7,代码来源:function.php


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