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


PHP mysqli_connect函数代码示例

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


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

示例1: mySqlUpit

function mySqlUpit($upit, $tip)
{
    $konekcija = mysqli_connect("localhost", "root", "", "0007cinevision");
    $konekcija->set_charset("utf8");
    if (mysqli_connect_errno()) {
        printf("Konekcija nije uspela: %s\n", mysqli_connect_error());
        exit;
    }
    $rezultat = mysqli_query($konekcija, $upit);
    if (!$rezultat) {
        printf("Greska: %s\n", mysqli_error($konekcija));
        exit;
    }
    if ($tip == 0) {
        return 0;
    }
    if ($tip == 1) {
        $rez = mysqli_fetch_array($rezultat, MYSQLI_NUM);
        $konekcija->close();
    } else {
        if ($tip == 2) {
            $rez = array();
            $i = 0;
            while (($red = mysqli_fetch_array($rezultat)) != NULL) {
                $rez[$i++] = $red;
            }
        }
    }
    if (!empty($rez)) {
        return $rez;
    }
    return -1;
}
开发者ID:laxsrbija,项目名称:Cinevision,代码行数:33,代码来源:mysql.php

示例2: connect

 function connect($server, $db, $user, $password, $socketPath, $charset = null, $port = false)
 {
     $connection = false;
     if ($socketPath !== false) {
         ini_set("mysqli.default_socket", $socketPath);
     }
     if ($this->UsePersistentConnection == true) {
         // Only supported on PHP 5.3 (mysqlnd)
         if (version_compare(PHP_VERSION, '5.3') > 0) {
             $this->Server = 'p:' . $this->Server;
         } else {
             eZDebug::writeWarning('mysqli only supports persistent connections when using php 5.3 and higher', 'eZMySQLiDB::connect');
         }
     }
     eZPerfLogger::accumulatorStart('mysqli_connection', 'mysqli_total', 'Database connection');
     $connection = mysqli_connect($server, $user, $password, null, (int) $port, $socketPath);
     $dbErrorText = mysqli_connect_error();
     eZPerfLogger::accumulatorStop('mysqli_connection');
     $maxAttempts = $this->connectRetryCount();
     $waitTime = $this->connectRetryWaitTime();
     $numAttempts = 1;
     while (!$connection && $numAttempts <= $maxAttempts) {
         sleep($waitTime);
         eZPerfLogger::accumulatorStart('mysqli_connection', 'mysqli_total', 'Database connection');
         $connection = mysqli_connect($this->Server, $this->User, $this->Password, null, (int) $this->Port, $this->SocketPath);
         eZPerfLogger::accumulatorStop('mysqli_connection');
         $numAttempts++;
     }
     $this->setError();
     $this->IsConnected = true;
     if (!$connection) {
         eZDebug::writeError("Connection error: Couldn't connect to database. Please try again later or inform the system administrator.\n{$dbErrorText}", __CLASS__);
         $this->IsConnected = false;
         throw new eZDBNoConnectionException($server);
     }
     if ($this->IsConnected && $db != null) {
         eZPerfLogger::accumulatorStart('mysqli_connection', 'mysqli_total', 'Database connection');
         $ret = mysqli_select_db($connection, $db);
         eZPerfLogger::accumulatorStop('mysqli_connection');
         if (!$ret) {
             //$this->setError();
             eZDebug::writeError("Connection error: " . mysqli_errno($connection) . ": " . mysqli_error($connection), "eZMySQLiDB");
             $this->IsConnected = false;
         }
     }
     if ($charset !== null) {
         $originalCharset = $charset;
         $charset = eZCharsetInfo::realCharsetCode($charset);
     }
     if ($this->IsConnected and $charset !== null) {
         eZPerfLogger::accumulatorStart('mysqli_connection', 'mysqli_total', 'Database connection');
         $status = mysqli_set_charset($connection, eZMySQLCharset::mapTo($charset));
         eZPerfLogger::accumulatorStop('mysqli_connection');
         if (!$status) {
             $this->setError();
             eZDebug::writeWarning("Connection warning: " . mysqli_errno($connection) . ": " . mysqli_error($connection), "eZMySQLiDB");
         }
     }
     return $connection;
 }
开发者ID:gggeek,项目名称:ezperformancelogger,代码行数:60,代码来源:ezmysqlitracingdb.php

示例3: cometchatDBConnect

function cometchatDBConnect()
{
    global $dbh;
    $port = DB_PORT;
    if (empty($port)) {
        $port = '3306';
    }
    $dbserver = explode(':', DB_SERVER);
    if (!empty($dbserver[1])) {
        $port = $dbserver[1];
    }
    $db_server = $dbserver[0];
    $dbh = mysqli_connect($db_server, DB_USERNAME, DB_PASSWORD, DB_NAME, $port);
    if (mysqli_connect_errno($dbh)) {
        $dbh = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME, $port, '/tmp/mysql5.sock');
    }
    if (mysqli_connect_errno($dbh)) {
        echo "<h3>Unable to connect to database due to following error(s). Please check details in configuration file.</h3>";
        if (!defined('DEV_MODE') || defined('DEV_MODE') && DEV_MODE != '1') {
            ini_set('display_errors', 'On');
            echo mysqli_connect_error($dbh);
            ini_set('display_errors', 'Off');
        }
        header('HTTP/1.1 503 Service Temporarily Unavailable');
        header('Status: 503 Service Temporarily Unavailable');
        header('Retry-After: 10');
        /* 10 seconds */
        exit;
    }
    mysqli_select_db($dbh, DB_NAME);
    mysqli_query($dbh, "SET NAMES utf8");
    mysqli_query($dbh, "SET CHARACTER SET utf8");
    mysqli_query($dbh, "SET COLLATION_CONNECTION = 'utf8_general_ci'");
}
开发者ID:albertoneto,项目名称:localhost,代码行数:34,代码来源:cometchat_shared.php

示例4: abrirConex

function abrirConex()
{
    global $conexion;
    // Conexión con el servidor de base de datos MySQL
    $conexion = mysqli_connect('localhost', 'root', '', 'auditoria');
    mysqli_set_charset($conexion, 'utf8');
}
开发者ID:JCarlosR,项目名称:AuditoriaPHP,代码行数:7,代码来源:funciones.php

示例5: db_connect

/**
   $host - hostname:port, hostname:socket, socket, where a socket is to be provided, the : is compulsory, even
   if its first character, in which case localhost is assumed
   
   @param $cache_link - if TRUE, save reference to link for reuse.
*/
function db_connect($host, $user, $passwd, $dbname, $cache_link = TRUE)
{
    global $_opendb_dblink;
    $index = strpos($host, ':');
    if ($index !== FALSE) {
        $port = substr($host, $index + 1);
        $host = substr($host, 0, $index);
        // probably a socket
        if (!is_numeric($port)) {
            $socket = $port;
            unset($port);
        }
    }
    if (strlen($socket) > 0) {
        $link = @mysqli_connect($host, $user, $passwd, $dbname, NULL, $socket);
    } else {
        if (strlen($port) > 0) {
            $link = @mysqli_connect($host, $user, $passwd, $dbname, $port);
        } else {
            $link = @mysqli_connect($host, $user, $passwd, $dbname);
        }
    }
    if ($link !== FALSE) {
        if ($cache_link) {
            $_opendb_dblink = $link;
        }
        return $link;
    }
    //else
    return FALSE;
}
开发者ID:robboor,项目名称:opendb,代码行数:37,代码来源:mysqli.inc.php

示例6: getRank

function getRank($a, $b, $c)
{
    include 'config.php';
    $con = mysqli_connect($IP, $user, $pass, $db);
    //		echo "select `idCategory` from Placed where `idBid`=$c and `idAuction`=$a";
    //		echo "select `idCategory` from Placed where `idBid`=$c and `idAuction`=$a";
    //echo "select `idCategory` from Placed where `idBid`=$c and `idAuction`=$a";
    //    	$result=mysqli_query($con,"select `idCategory` from Placed where `idBid`=$c and `idAuction`=$a") or die(mysqli_error($con));
    $result = mysqli_query($con, "select `idCategory` from Placed where `idBid`={$c} and `idAuction`={$a}") or die(mysqli_error($con));
    //		echo "select count(*)+1 as rank from Placed where `Price`>$b and `idAuction`=$a and `status` =  'A'";
    //		echo json_encode($result);
    //		echo mysqli_num_rows($result);
    $row = mysqli_fetch_assoc($result);
    $c = $row['idCategory'];
    //        echo $c.'sdf';
    if (empty($c)) {
        return 0;
    }
    //		echo "select count(*)+1 as rank from Placed where `Price`>$b and `idCategory`=$c and `idAuction`=$a and `status` =  'A'";
    //echo "select count(*)+1 as rank from Placed where `Price`>$b and `idCategory`=$c and `idAuction`=$a and `status` =  'A'";
    $result = mysqli_query($con, "select count(*)+1 as rank from Placed where `Price`>{$b} and `idCategory`={$c} and `idAuction`={$a} and `status` =  'A'") or die("Error" . mysqli_error($con));
    $output = [];
    while ($row = mysqli_fetch_assoc($result)) {
        return $row['rank'];
    }
}
开发者ID:jeevan6,项目名称:CSL343_Networking_Errands,代码行数:26,代码来源:getRank.php

示例7: conexion

 public function conexion()
 {
     if (!isset($this->con)) {
         $this->con = mysqli_connect("localhost", "root", "", "inventiba") or die(mysqli_error());
         //echo "Conexion exitosa";
     }
 }
开发者ID:KrolCi,项目名称:MiniApp,代码行数:7,代码来源:Mysql.php

示例8: insertDatabaseFunc

function insertDatabaseFunc($username, $password, $queryType, $entity)
{
    require_once 'queryDatabaseHelper.php';
    if (validUsernameAndPassword($username, $password)) {
        $link = mysqli_connect("localhost", "Tommy", "pickles", "Model");
        if (strcmp($queryType, 'Unsubs') == 0) {
            $query = 'DELETE FROM `subscription` WHERE `username`=\'' . $username . '\' AND `orgnumber`=\'' . $entity . '\'';
        } elseif (strcmp($queryType, 'RSVP') == 0) {
            $query = 'INSERT IGNORE INTO `rsvp`(`username`, `eventnumber`) VALUES (\'' . $username . '\',' . $entity . ')';
        } elseif (strcmp($queryType, 'Subs') == 0) {
            $query = 'INSERT INTO `subscription`(`username`, `orgnumber`) VALUES (\'' . $username . '\',\'' . $entity . '\')';
        } elseif (strcmp($queryType, 'AndroidDevice') == 0) {
            $query = 'INSERT IGNORE INTO `androiddevice`(`username`, `device_id`) VALUES (\'' . $username . '\',\'' . $entity . '\')';
        }
        if (mysqli_connect_errno()) {
            printf("Connect failed: %s\n", mysqli_connect_error());
            exit;
        }
        if (mysqli_query($link, $query)) {
            echo 'true';
        } else {
            echo 'false';
        }
        mysqli_close($link);
    } else {
        echo 'false';
    }
}
开发者ID:dongreenberg,项目名称:Bookie,代码行数:28,代码来源:insertDatabaseHelper.php

示例9: __construct

 /**
  * Class constructor. Connects to Databaseserver and selects Database.
  *
  * @param string Servername
  * @param string Username
  * @param string Password
  * @param string Database
  */
 public function __construct($server, $user, $password, $database = '')
 {
     // check for mysql extension
     if (!extension_loaded('mysqli')) {
         $this->showerror('You should install the PHP MySQLi extension!', false);
     }
     $this->server = $server;
     $this->user = $user;
     $this->password = $password;
     $this->database = $database;
     $this->link_id = @($GLOBALS['___mysqli_ston'] = mysqli_connect($this->server, $this->user, $this->password));
     if (!$this->link_id) {
         //try to connect with no password an change it afterwards. only for root user
         if ($this->user == 'root') {
             $this->link_id = @($GLOBALS['___mysqli_ston'] = mysqli_connect($this->server, $this->user, ''));
             if ($this->link_id) {
                 $this->query("SET PASSWORD = PASSWORD('" . $this->escape($this->password) . "')");
             } else {
                 $this->showerror('Establishing connection failed, exiting');
             }
         } else {
             $this->showerror('Establishing connection failed, exiting');
         }
     }
     if ($this->database != '') {
         if (!@(bool) mysqli_query($this->link_id, 'USE ' . $this->database)) {
             $this->showerror('Trying to use database ' . $this->database . ' failed, exiting');
         }
     }
 }
开发者ID:markc,项目名称:syscp,代码行数:38,代码来源:class.db.php

示例10: setNewServer

 public function setNewServer($host, $user, $password, $database, $faild = self::EXCEPTION_FAILD_MODE)
 {
     //$this->server=null;
     //
     if ($host == "" and $user == "" and $database == "") {
         throw new DatabaseArgumentsException();
     } else {
         Database::$server = mysqli_connect($host, $user, $password, $database);
         //
         if (!Database::$server) {
             if ($faild == 2 && Config::get('panel.configured')) {
                 throw new DatabaseConnectionException();
             } else {
                 if ($faild == 1) {
                     \Errors::r_db();
                 }
             }
         }
         //
         mysqli_query(Database::$server, "SET NAMES " . Config::get("database.charset"));
         //
         Database::$serverData = ['host' => $host, "username" => $user, "password" => $password, "database" => $database];
         //
         //
         return Database::$server;
     }
 }
开发者ID:ar-framework-labs,项目名称:kernel,代码行数:27,代码来源:MySql.php

示例11: open_connection

 public function open_connection()
 {
     $this->connection = mysqli_connect('localhost', 'root', '', 'projectbrowser');
     if (mysqli_connect_errno()) {
         die("Database connection failed: " . mysqli_connect_error() . " (" . mysqli_connect_errno() . ")");
     }
 }
开发者ID:lghenk,项目名称:projectbrowser,代码行数:7,代码来源:database.php

示例12: connect

 function connect($db_type, $var1 = false, $var2 = false, $var3 = false, $var4 = false, $var5 = '')
 {
     global $db_connected, $pdo, $mysql_connect, $mysql_select_db, $db_type1, $db_prefix;
     $db_type1 = $db_type;
     $db_prefix = $var5;
     switch ($db_type) {
         case 'mysql':
             # var1 = db_host | var2 = db_user | var3 = db_pass | var4 = db_name | var5 = db_prefix
             try {
                 $pdo = new PDO("mysql:host={$var1};dbname={$var4};charset=utf8", $var2, $var3);
                 $db_connected = true;
             } catch (PDOException $e) {
                 die("ERROR: 001");
             }
             break;
         case 'sqlite':
             # var1 = db_path
             try {
                 $pdo = new PDO("sqlite:{$var1}");
                 $db_connected = true;
             } catch (PDOException $e) {
                 die("ERROR: 001");
             }
             break;
         case 'mysqli':
             # var1 = db_host | var2 = db_user | var3 = db_pass | var4 = db_name | var5 = db_prefix
             $mysql_connect = mysqli_connect($var1, $var2, $var3, $var4) or die("ERROR: 001");
             if ($mysql_connect) {
                 mysqli_select_db($mysql_connect, $var4) or die("ERROR: 002");
                 mysqli_query($mysql_connect, "SET NAMES 'utf8'");
                 $db_connected = true;
             }
             break;
     }
 }
开发者ID:rocketpastsix,项目名称:foxycms,代码行数:35,代码来源:databases.php

示例13: __construct

 function __construct()
 {
     $this->connection = mysqli_connect($this->host, $this->user, $this->pass, $this->name);
     if (mysqli_connect_errno($this->connection)) {
         echo "Failed to connect to MySQL: " . mysqli_connect_error();
     }
 }
开发者ID:andregimenez,项目名称:Capri,代码行数:7,代码来源:databaseHelper.php

示例14: __construct

 /**
  * 
  * @param string $db_server
  * @param string $db_user
  * @param string $db_password
  * @param bool|int $db_persist
  */
 public function __construct($db_server, $db_user, $db_password, $db_persist)
 {
     $this->con = mysqli_connect(($db_persist == 1 ? 'p:' : '') . $db_server, $db_user, $db_password);
     if (mysqli_connect_error()) {
         die('Database error: ' . mysqli_connect_error());
     }
 }
开发者ID:kddlb,项目名称:openimporter,代码行数:14,代码来源:Database.php

示例15: open_connection

 public function open_connection()
 {
     $this->connection = mysqli_connect(DB_SERVER, DB_USER, DB_PASS, DB_DBNAME);
     if (!$this->connection) {
         die("Database Connection Failed " . mysqli_error());
     }
 }
开发者ID:kamalrazalatif,项目名称:teambook,代码行数:7,代码来源:database_orig.php


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