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


PHP mysqli_connect_error函数代码示例

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


在下文中一共展示了mysqli_connect_error函数的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: connect

 /**
  * 连接数据库方法
  * @access public
  * @throws ThinkExecption
  */
 public function connect($config = '', $linkNum = 0)
 {
     if (!isset($this->linkID[$linkNum])) {
         if (empty($config)) {
             $config = $this->config;
         }
         $this->linkID[$linkNum] = new \mysqli($config['hostname'], $config['username'], $config['password'], $config['database'], $config['hostport'] ? intval($config['hostport']) : 3306);
         if (mysqli_connect_errno()) {
             E(mysqli_connect_error());
         }
         $dbVersion = $this->linkID[$linkNum]->server_version;
         // 设置数据库编码
         $this->linkID[$linkNum]->query("SET NAMES '" . $config['charset'] . "'");
         //设置 sql_model
         if ($dbVersion > '5.0.1') {
             $this->linkID[$linkNum]->query("SET sql_mode=''");
         }
         // 标记连接成功
         $this->connected = true;
         //注销数据库安全信息
         if (1 != C('DB_DEPLOY_TYPE')) {
             unset($this->config);
         }
     }
     return $this->linkID[$linkNum];
 }
开发者ID:hongchonglhm,项目名称:APICloud-ThinkPHP-SDK,代码行数:31,代码来源:Mysqli.class.php

示例4: __construct

 public function __construct()
 {
     $this->connnection = mysqli_connect('localhost', 'root', 'prafful', 'assignment2');
     if (mysqli_connect_error()) {
         trigger_error("database connection failed" . mysqli_connect_error(), E_USER_ERROR);
     }
 }
开发者ID:Prafful-p,项目名称:php,代码行数:7,代码来源:database.php

示例5: 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

示例6: __construct

		function __construct(/*$database = null*/) {
			# ранее подключение не происходило при каждом запросе
			# а только при создании класса $db

			# теперь же я подключение создается только при первом обращении к БД через метод $this->call(), все остальные методы либо не обращаютяс к БД либо обращаются к ней через него
			# это позволяет избежать лишних подключений к БД при каждом запросе страницы, если БД не используется
			# для этого подключение пытается создать толкьо при вызове $this->call(), который предварительно проверяет не было ли создано подключение ранее
			# в дальшейшем при обращении к БД ипользуется уже созданное подключение

			global $database;
			// if (empty($database)) {
				// $database = $GLOBALS['database'];
			// }
			if (empty($this->link)) {
				try {
					$this->link = new mysqli(
						 $database['host']
						,$database['user']
						,$database['pass']
						#,$database['name']
					);
				}
				catch(mysqli_sql_exception $e) {
					// $lang->give('mysqlerr');
					global $error;
					$error->report('Ошибка при подключении к Базе данных: ' . mysqli_connect_error() . ' :: ' . $e->getCode(), __LINE__, 'Fatal Error', $e->getCode());
				}
			}
			$query = "CREATE DATABASE IF NOT EXISTS `${database['name']}` CHARACTER SET utf8 COLLATE utf8_general_ci";
			$this->link->query($query);
			$this->link->select_db($database['name']);
			# неплохо бы сперва узнать есть база или нет, нету создавать её,записать лог, а уже потом выбирать её.
			$this->link->set_charset("utf8");

			// $dns = $database['driver'];
			// $dns .= ':host=' . $database['host'];
			// $dns .= (($database['port']) ? (';port=' . $database['port']) : '');
			// $dns .= ';dbname=' . $database['name'];
			// # SQLite  имеет другой синтаксис.... $DBH = new PDO("sqlite:my/database/path/database.db");

			// try {
			// 	$line = __LINE__ + 1;
			// 	$DBH = new PDO($dns, $database['user'], $database['pass']);
			// 	$DBH->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
			// }
			// catch(PDOException $e) {
			// 	global $error;
			// 	$error->report($e->getMessage(), $line, 'Fatal Error', __FILE__);
			// }

			#$query = "CREATE DATABASE IF NOT EXISTS `${mysql['db']}` CHARACTER SET utf8 COLLATE utf8_general_ci;";

	// $mysqli = mysqli_init()
	// 	or die($msg['error']['mysqli']['init']);
 // 	$mysqli->real_connect($database['host'], $database['user'], $database['pass'])
	// 	or die($msg['error']['mysqli']['real_connect']);
	// $mysqli->select_db($database['name'])
	// 	or die($msg['error']['mysqli']['select_db']);

		}
开发者ID:Adeptx,项目名称:adeptx_core,代码行数:60,代码来源:db.php

示例7: connect

 /**
 +----------------------------------------------------------
 * 连接数据库方法
 +----------------------------------------------------------
 * @access public
 +----------------------------------------------------------
 * @throws ThinkExecption
 +----------------------------------------------------------
 */
 public function connect($config = '', $linkNum = 0)
 {
     if (!isset($this->linkID[$linkNum])) {
         if (empty($config)) {
             $config = $this->config;
         }
         $this->linkID[$linkNum] = new mysqli($config['hostname'], $config['username'], $config['password'], $config['database'], $config['hostport']);
         if (mysqli_connect_errno()) {
             throw_exception(mysqli_connect_error());
         }
         $dbVersion = $this->linkID[$linkNum]->server_version;
         if ($dbVersion >= "4.1") {
             // 设置数据库编码 需要mysql 4.1.0以上支持
             $this->linkID[$linkNum]->query("SET NAMES '" . C('DB_CHARSET') . "'");
         }
         //设置 sql_model
         if ($dbVersion > '5.0.1') {
             $this->linkID[$linkNum]->query("SET sql_mode=''");
         }
         // 标记连接成功
         $this->connected = true;
         //注销数据库安全信息
         if (1 != C('DB_DEPLOY_TYPE')) {
             unset($this->config);
         }
     }
     return $this->linkID[$linkNum];
 }
开发者ID:dalinhuang,项目名称:concourse,代码行数:37,代码来源:DbMysqli.class.php

示例8: __construct

 public function __construct()
 {
     $this->_connection = new mysqli($host, $user, $password, $database, $port, $socket);
     if (mysqli_connect_error()) {
         trigger_error('There was an error connecting to database' . mysqli_connect_error());
     }
 }
开发者ID:Edwinamakobe,项目名称:kleva,代码行数:7,代码来源:DatabaseConnection.php

示例9: makeDb

function makeDb()
{
    // THIS SHOULD ONLY BE USED IN DEV ENVIRONMENT!!!!
    // NEEDS TO BE CHANGED WHEN USED TO UPDATE THE SERVER!!
    $con = new mysqli("localhost", "root", "", "nhvbsr");
    if (mysqli_connect_errno()) {
        echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }
    //Call our function to get the assoc array....
    $statements = setupSQL();
    //I added this crappy noob workaround because I'm lazy and don't have time
    //to do it the right way...
    // The script was failing because it was trying to add foreign keys
    //before the reference table existed
    // so now we make all the tables, then go back and make them again with
    // all their relative foreign keys... Like I said its a terrible way.
    foreach ($statements as $queries) {
        //okay loop through... each value is a sql query so execute it...
        foreach ($queries as $key => $val) {
            $res = $con->query($val);
            // prep the statement for security....
            if ($stmt = $con->prepare($val)) {
                $stmt->execute();
            }
            //if it was no good print the error....
            if (!$res) {
                printf("<br /> Error at Key: {$key}: %s\n", $con->error);
            } else {
                echo "<br /> The table '{$key}' was successfully created! <br />";
            }
        }
    }
}
开发者ID:ChromeTemplar,项目名称:nhlakes_unhm,代码行数:33,代码来源:createNhvbsrDB.php

示例10: __construct

 public function __construct()
 {
     $this->con = new mysqli(__HOST__, __USER__, __PASS__, __BASE__);
     if (mysqli_connect_errno()) {
         die("DB connection failed:" . mysqli_connect_error());
     }
 }
开发者ID:yubarajshrestha,项目名称:DatabaseWithAngular,代码行数:7,代码来源:config.php

示例11: DatabaseSettings

 public function DatabaseSettings()
 {
     $this->connection = new mysqli("localhost", "souvenirs1925", "souvenirs1925", "souvenirs1925");
     if (mysqli_connect_error()) {
         trigger_error("DB Error");
     }
 }
开发者ID:akbars95,项目名称:phpProjects,代码行数:7,代码来源:DatabaseSettings.php

示例12: __construct

 private function __construct($connect)
 {
     if (empty($connect)) {
         if ($GLOBALS["i"]["dev"]) {
             $host = "localhost";
             $user = "root";
             $pass = "funkytown";
             $db = "bijoux";
         } else {
             $host = "localhost";
             $user = "nickand5_admin";
             $pass = "v0h1t099";
             $db = "nickand5_bijoux";
         }
     } else {
         $host = $connect["host"];
         $user = $connect["user"];
         $pass = $connect["pass"];
         $db = $connect["db"];
     }
     //Connect to db
     $this->db = mysqli_connect($host, $user, $pass, $db);
     if (mysqli_connect_error()) {
         die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error());
     }
 }
开发者ID:nac80,项目名称:bijoux-website,代码行数:26,代码来源:NDB.php

示例13: con_sql

function con_sql($sqlip, $sqlid, $sqlpass)
{
    @($con = new mysqli($sqlip, $sqlid, $sqlpass));
    if (mysqli_connect_errno()) {
        die(mysqli_connect_error());
    }
}
开发者ID:qinmenghua,项目名称:shudong-share,代码行数:7,代码来源:function.php

示例14: __construct

 public function __construct()
 {
     $this->con = mysqli_connect("localhost", "root", "123456", "passgen");
     if (mysqli_connect_errno()) {
         die("Failed to connect to MySQL: " . mysqli_connect_error());
     }
 }
开发者ID:hemnathmouli,项目名称:Password-Generate-and-save-into-SQL,代码行数:7,代码来源:functions.php

示例15: connect

 private function connect()
 {
     $this->db_connect_id = mysqli_connect($this->obj['dbhost'], $this->obj['dbuser'], $this->obj['dbpwd'], $this->obj['dbname']);
     if (!$this->db_connect_id) {
         echo " Error no se puede conectar al servidor:" . mysqli_connect_error();
     }
 }
开发者ID:AngelMtz1,项目名称:SkyBookMVC,代码行数:7,代码来源:config.inc.php


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