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


PHP mysqli::select_db方法代码示例

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


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

示例1: open

 public function open($save_path, $session_id)
 {
     if ($this->connection === null) {
         $this->connection = new \mysqli($this->config['host'], $this->config['user'], $this->config['pass']);
         $this->connection->select_db($this->config['database']);
     }
 }
开发者ID:aainc,项目名称:Hoimi,代码行数:7,代码来源:DatabaseDriver.php

示例2: __construct

 public function __construct()
 {
     $this->conn = mysqli_connect(config::val("db_ip"), config::val("db_user"), config::val("db_pass")) or die("mysqli_connect 1");
     $this->create_database();
     $this->conn->select_db("smarttable");
     $this->create_tables();
 }
开发者ID:johnjsb,项目名称:Liatris,代码行数:7,代码来源:db.php

示例3: opendatabase

function opendatabase($dataname)
{
    global $inifile;
    //Connection pointer to sql
    $sqlc = new mysqli($inifile["conndet"]["server"], $inifile["conndet"]["user"], $inifile["conndet"]["pass"]);
    //Checking if connection is good
    if ($sqlc->connect_errno) {
        return errlog("Error: " . $sqlc->connect_errno . " Failed to connect to server " . $inifile["conndet"]["server"] . ".");
    }
    //attempting to open database
    if (!$sqlc->select_db($dataname)) {
        //If connection fails run this
        //If autocreate is false
        if (!$inifile["mysqlval"]["autocreate"]) {
            return errlog("Database {$dataname} does not exist.");
        } else {
            //If not create new one
            errlog("Database does not exist. Creating database {$dataname}");
            //Checking if new data base was created
            if (!$sqlc->query('CREATE DATABASE ' . $dataname)) {
                //If not then log failed
                return errlog("Error: " . $sqlc->error . " Failed to create database: {$dataname}");
            } else {
                $sqlc->select_db($dataname);
            }
            return $sqlc;
        }
    } else {
        //Conncetion succeeded
        return $sqlc;
    }
}
开发者ID:bthepuma117,项目名称:TechBark-Website,代码行数:32,代码来源:sqlfunc.php

示例4: setDatabase

 /**
  * Set the database.
  *
  * @param string $db
  * @return bool success
  */
 public function setDatabase($db)
 {
     if ($this->conn->connect_error) {
         return false;
     }
     return @$this->conn->select_db($db);
 }
开发者ID:prepare4battle,项目名称:Ilch-2.0,代码行数:13,代码来源:Mysql.php

示例5: dbconnect

 /**
  * This method makes sure to connect to the database properly
  *
  * @param string $strHost
  * @param string $strUsername
  * @param string $strPass
  * @param string $strDbName
  * @param int $intPort
  *
  * @return bool
  * @throws class_exception
  */
 public function dbconnect($strHost, $strUsername, $strPass, $strDbName, $intPort)
 {
     if ($intPort == "") {
         $intPort = "3306";
     }
     //save connection-details
     $this->strHost = $strHost;
     $this->strUsername = $strUsername;
     $this->strPass = $strPass;
     $this->strDbName = $strDbName;
     $this->intPort = $intPort;
     $this->linkDB = @new mysqli($strHost, $strUsername, $strPass, $strDbName, $intPort);
     if ($this->linkDB !== false) {
         if (@$this->linkDB->select_db($strDbName)) {
             //erst ab mysql-client-bib > 4
             //mysqli_set_charset($this->linkDB, "utf8");
             $this->_pQuery("SET NAMES 'utf8'", array());
             $this->_pQuery("SET CHARACTER SET utf8", array());
             $this->_pQuery("SET character_set_connection ='utf8'", array());
             $this->_pQuery("SET character_set_database ='utf8'", array());
             $this->_pQuery("SET character_set_server ='utf8'", array());
             return true;
         } else {
             throw new class_exception("Error selecting database", class_exception::$level_FATALERROR);
         }
     } else {
         throw new class_exception("Error connecting to database", class_exception::$level_FATALERROR);
     }
 }
开发者ID:jinshana,项目名称:kajonacms,代码行数:41,代码来源:class_db_mysqli.php

示例6: connect

 /**
  * @see Lumine_Connection_IConnection::connect()
  */
 public function connect()
 {
     if ($this->conn && $this->state == self::OPEN) {
         Lumine_Log::debug('Utilizando conexao cacheada com ' . $this->getDatabase());
         $this->conn->select_db($this->getDatabase());
         return true;
     }
     $this->dispatchEvent(new Lumine_Events_ConnectionEvent(Lumine_Event::PRE_CONNECT, $this));
     $hostString = $this->getHost();
     if ($this->getPort() != '') {
         $hostString .= ':' . $this->getPort();
     }
     if (isset($this->options['socket']) && $this->options['socket'] != '') {
         $hostString .= ':' . $this->options['socket'];
     }
     $flags = isset($this->options['flags']) ? $this->options['flags'] : null;
     if (isset($this->options['persistent']) && $this->options['persistent'] == true) {
         $hostString = 'p:' . $hostString;
     }
     Lumine_Log::debug('Criando conexao com ' . $this->getDatabase());
     $this->conn = new mysqli($this->getHost(), $this->getUser(), $this->getPassword(), $this->getDatabase());
     if ($this->conn->connect_error) {
         $this->state = self::CLOSED;
         $msg = 'nao foi possivel conectar no banco de dados: ' . $this->getDatabase() . ' - ' . $this->conn->connect_error;
         Lumine_Log::error($msg);
         $this->dispatchEvent(new Lumine_Events_ConnectionEvent(Lumine_Event::CONNECTION_ERROR, $this, $msg));
         throw new Exception($msg);
         return false;
     }
     // seleciona o banco
     $this->state = self::OPEN;
     $this->setCharset($this->getCharset());
     $this->dispatchEvent(new Lumine_Events_ConnectionEvent(Lumine_Event::POS_CONNECT, $this));
     return true;
 }
开发者ID:bladerangel,项目名称:aplicacao,代码行数:38,代码来源:MySQLi.php

示例7: changeDb

 /**
  * Changes current database
  * @param  string  $database database name
  * @return boolean true on success, false - otherwise
  */
 public function changeDb($database)
 {
     if ($this->conn->select_db($database)) {
         return true;
     }
     return false;
 }
开发者ID:ambient-lounge,项目名称:site,代码行数:12,代码来源:Mysqli.php

示例8: open

 /**
  * connect database
  */
 public function open()
 {
     if ($this->connection === null) {
         $this->driver = new \mysqli_driver();
         $this->driver->report_mode = MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT;
         $this->connection = new \mysqli($this->config['host'], $this->config['user'], $this->config['pass']);
         $this->connection->select_db($this->config['database']);
     }
 }
开发者ID:aainc,项目名称:Mahotora,代码行数:12,代码来源:DatabaseSessionImpl.php

示例9: realConnect

 /**
  * Реализация установки соединения с базой
  * @throws Exception
  */
 protected function realConnect()
 {
     $this->db = @new \mysqli(!empty($this->config['hostname']) ? 'p:' . $this->config['hostname'] : '', $this->config['username'], $this->config['password']);
     if ($this->db->connect_error) {
         throw new Exception($this->error = $this->db->connect_error);
     }
     $this->db->set_charset('utf8');
     if (!$this->db->select_db($this->config['database'])) {
         throw new Exception($this->error = $this->db->error);
     }
 }
开发者ID:difra-org,项目名称:difra,代码行数:15,代码来源:MySQLi.php

示例10: init_mysql_connect

 /** begins the MySQL connection
  * @param bool $create_db
  * @throws DBMySQLException
  */
 private function init_mysql_connect($create_db = FALSE)
 {
     $this->connect = new mysqli($this->host, $this->user, $this->pass, NULL, $this->port);
     if ($this->connect->connect_errno > 0) {
         throw new DBMySQLException('Unable to connect to MySQL server reason: ' . $this->connect->connect_error, 1);
     }
     $this->connect->set_charset($this->encoding);
     if ($create_db) {
         $this->connect->query('CREATE DATABASE IF NOT EXISTS ' . $this->format_table_or_database_string($this->db_name));
     }
     $this->connect->select_db($this->db_name);
 }
开发者ID:heirteir,项目名称:MySQLDB,代码行数:16,代码来源:MySQLDB.php

示例11: vConnectDB

function vConnectDB($sDBName)
{
    global $mysqli;
    ##$mysqli = new mysqli( "localhost", "root", "John0316", "test" );
    $mysqli = new mysqli("p:localhost", "root", "bb4587", "baboom");
    // p: stands for persistent DB connection.
    // When there is too many connections,  this can lower the
    // overhead.  However,  extra server has to be increased right away
    // because it can create DB connection error or DB table lock. (12-26-14)
    ######
    # 12-12-14  Gets the error number of the connection.
    ######
    #if (mysqli_connect_errno())
    if ($mysqli->connect_errno) {
        printf("Connect failed: %s\n", $mysqli->connect_errno);
        exit;
    }
    #######
    # 12-12-14 Now use a database.  If the DB doesn't exists, exit out
    #          of the program.
    #######
    $bResult = $mysqli->select_db($sDBName);
    if ($bResult == FALSE) {
        printf("{$sDBName} database doesn't exists. \n");
        exit;
    }
}
开发者ID:nguaki,项目名称:baboom,代码行数:27,代码来源:ConnectDB.php

示例12: db_connect

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;
}
开发者ID:tmshort,项目名称:trees,代码行数:30,代码来源:mysql.php

示例13: modificaCoche

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;
    }
}
开发者ID:rubenet86,项目名称:projecteAutoEscola,代码行数:31,代码来源:cochesModelo.php

示例14: step3

 private function step3()
 {
     $mysqli = new mysqli("localhost", 'root', '');
     $mysqli->select_db("kongcms");
     $mysqli->query("set names utf8");
     //Tools::dump($mysqli);
     if (isset($_POST['send'])) {
         $sql = "update     admin \r\n\t\t\t\t  set        username='" . $_POST['admin_user'] . "',\r\n\t\t\t\t             pwd='" . md5($_POST['admin_pwd']) . "',\r\n\t\t\t\t\t         last_ip='" . $_SERVER['REMOTE_ADDR'] . "',\r\n\t\t\t\t\t         last_time=now(),\r\n\t\t\t\t\t         login_num=1,\r\n\t\t\t\t\t         reg_time=now()\r\n\t\t\t\t  where      username='admin'";
         /* $sql="insert into admin(
         							username,
         							pwd,
         							last_ip,
         							last_time,
         							login_num,
         							level_id,
         							reg_time
         			)values(
         					'".$_POST['admin_user']."',
         					'".md5($_POST['admin_pwd'])."',
         					'".$_SERVER['REMOTE_ADDR']."',
         					now(),
         					1,
         					3,
         					now()
         			)"; */
         if ($mysqli->query($sql)) {
             Tools::Redirect("后台管理员添加成功", "?a=install&action=step4");
         } else {
             Tools::Redirect("后台管理员添加失败", "?a=install&action=step3");
         }
     }
     $this->smarty->assign("step3", true);
 }
开发者ID:kongxiangrui,项目名称:webonly,代码行数:33,代码来源:installAction.class.php

示例15: __construct

 public function __construct()
 {
     $config = App::$config['database'];
     $db = new mysqli($config['server'], $config['username'], $config['password']);
     $db->select_db($config['database']);
     $this->db = $db;
 }
开发者ID:jnethery,项目名称:angular-blog,代码行数:7,代码来源:Database.php


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