本文整理汇总了PHP中mssql_select_db函数的典型用法代码示例。如果您正苦于以下问题:PHP mssql_select_db函数的具体用法?PHP mssql_select_db怎么用?PHP mssql_select_db使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mssql_select_db函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: connect
/**
+----------------------------------------------------------
* 连接数据库方法
+----------------------------------------------------------
* @access public
+----------------------------------------------------------
* @throws ThinkExecption
+----------------------------------------------------------
*/
public function connect($config = '', $linkNum = 0)
{
if (!isset($this->linkID[$linkNum])) {
if (empty($config)) {
$config = $this->config;
}
$conn = $this->pconnect ? 'mssql_pconnect' : 'mssql_connect';
// 处理不带端口号的socket连接情况
$host = $config['hostname'] . ($config['hostport'] ? ":{$config['hostport']}" : '');
$this->linkID[$linkNum] = $conn($host, $config['username'], $config['password']);
if (!$this->linkID[$linkNum]) {
throw_exception($this->error());
return false;
}
if (!mssql_select_db($config['database'], $this->linkID[$linkNum])) {
throw_exception($this->error());
return false;
}
// 标记连接成功
$this->connected = true;
//注销数据库安全信息
if (1 != C('DB_DEPLOY_TYPE')) {
unset($this->config);
}
}
return $this->linkID[$linkNum];
}
示例2: select
function select($db)
{
if (FALSE == mssql_select_db($db)) {
$this->print_error("<ol><b>Error establishing a database connection!</b><li>Are you sure you have the correct user/password?<li>Are you sure that you have typed the correct hostname?<li>Are you sure that the database server is running?</ol>");
die;
}
}
示例3: sql_connect
/**
* Connect to server
*/
function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false, $new_link = false)
{
if (!function_exists('mssql_connect')) {
$this->connect_error = 'mssql_connect function does not exist, is mssql extension installed?';
return $this->sql_error('');
}
$this->persistency = $persistency;
$this->user = $sqluser;
$this->dbname = $database;
$port_delimiter = defined('PHP_OS') && substr(PHP_OS, 0, 3) === 'WIN' ? ',' : ':';
$this->server = $sqlserver . ($port ? $port_delimiter . $port : '');
@ini_set('mssql.charset', 'UTF-8');
@ini_set('mssql.textlimit', 2147483647);
@ini_set('mssql.textsize', 2147483647);
if (version_compare(PHP_VERSION, '5.1.0', '>=') || version_compare(PHP_VERSION, '5.0.0-dev', '<=') && version_compare(PHP_VERSION, '4.4.1', '>=')) {
$this->db_connect_id = $this->persistency ? @mssql_pconnect($this->server, $this->user, $sqlpassword, $new_link) : @mssql_connect($this->server, $this->user, $sqlpassword, $new_link);
} else {
$this->db_connect_id = $this->persistency ? @mssql_pconnect($this->server, $this->user, $sqlpassword) : @mssql_connect($this->server, $this->user, $sqlpassword);
}
if ($this->db_connect_id && $this->dbname != '') {
if (!@mssql_select_db($this->dbname, $this->db_connect_id)) {
@mssql_close($this->db_connect_id);
return false;
}
}
return $this->db_connect_id ? $this->db_connect_id : $this->sql_error('');
}
示例4: connect
/**
* {@inheritdoc}
*/
public function connect()
{
$config = $this->config;
$config = array_merge($this->baseConfig, $config);
$os = env('OS');
if (!empty($os) && strpos($os, 'Windows') !== false) {
$sep = ',';
} else {
$sep = ':';
}
$this->connected = false;
if (is_numeric($config['port'])) {
$port = $sep . $config['port'];
// Port number
} elseif ($config['port'] === null) {
$port = '';
// No port - SQL Server 2005
} else {
$port = '\\' . $config['port'];
// Named pipe
}
if (!$config['persistent']) {
$this->connection = mssql_connect($config['host'] . $port, $config['username'], $config['password'], true);
} else {
$this->connection = mssql_pconnect($config['host'] . $port, $config['username'], $config['password']);
}
if (mssql_select_db($config['database'], $this->connection)) {
$this->qery('SET DATEFORMAT ymd');
$this->connected = true;
}
return $this->connection;
}
示例5: _connect
/**
* Creates a connection resource.
*/
protected function _connect()
{
if (is_resource($this->_connection)) {
// connection already exists
return;
}
if (!extension_loaded('mssql')) {
throw new Exception('The mssql extension is required for this adapter but the extension is not loaded');
}
$serverName = $this->_config['host'];
if (isset($this->_config['port'])) {
$port = (int) $this->_config['port'];
$serverName .= ', ' . $port;
}
$username = $password = '';
if (isset($this->_config['username']) && isset($this->_config['password'])) {
$username = $this->_config['username'];
$password = $this->_config['password'];
}
$this->_connection = mssql_connect($serverName, $username, $password);
if (!$this->_connection) {
throw new Exception('Mssql Connection Error: ' . mssql_get_last_message());
}
if (isset($this->_config['dbname']) && !mssql_select_db($this->_config['dbname'])) {
throw new Exception('Unable to connect or select database ' . $this->_config['dbname']);
}
}
示例6: __construct
/**
* Constructor
*
* @param $dsn string DSN for the connection
*/
public function __construct($dsn)
{
$this->config = parse_url($dsn);
if (!$this->config) {
throw new DatabaseException("Invalid dsn '{$dsn}'.");
}
$database = trim($this->config['path'], '/');
if (isset($this->config['host'])) {
$host = $this->config['host'];
}
if (isset($this->config['user'])) {
$user = $this->config['user'];
}
if (isset($this->config['port'])) {
$port = $this->config['port'];
}
if (isset($this->config['pass'])) {
$pass = $this->config['pass'];
}
$this->connection = mssql_connect($host, $user, $pass);
if (!$this->connection) {
throw new DatabaseException("Invalid database settings.");
}
if (!mssql_select_db($database, $this->connection)) {
throw new DatabaseException("Database does not exist");
}
}
示例7: getProductos
function getProductos()
{
$myServer = "172.30.5.49";
$myUser = "UsrPsg";
$myPass = "PsGcRm1402*LaU+";
$myDB = "LAUMAYER";
$dbhandle = mssql_connect($myServer, $myUser, $myPass) or die("Couldn't connect to SQL Server on {$myServer}");
$selected = mssql_select_db($myDB, $dbhandle) or die("Couldn't open database {$myDB}");
//Realiza el query en la base de datos
$mysqli = makeSqlConnection();
//$sql = "SELECT * FROM psg_productos a LEFT JOIN psg_productos_cstm ac ON a.id = ac.id_c";
$sql = "SELECT id,name FROM psg_productos where deleted ='0'";
$res = $mysqli->query($sql);
$rows = array();
while ($r = mysqli_fetch_assoc($res)) {
$obj = (object) $r;
$querySaldo = "Select dbo.F_Saldo_Bodega_Informe(Year(GETDATE()),MONTH(GETDATE()),'" . $r['id'] . "','BODPRDCTO','T','C') as Saldo";
$result = mssql_query($querySaldo);
if ($row = mssql_fetch_array($result)) {
$obj->saldo = $row['Saldo'];
}
$a = (array) $obj;
$rows[] = $a;
}
mssql_close($dbhandle);
if (empty($rows)) {
return '{"results" :[]}';
} else {
//Convierte el arreglo en json y lo retorna
$temp = json_encode(utf8ize($rows));
return '{"results" :' . $temp . '}';
}
}
示例8: conn
function conn($DB)
{
$serverName = "intelisis";
//serverName\instanceName
$connectionInfo = array("Database" => $DB, "UID" => "intelisis", "PWD" => "");
$conn = mssql_connect($serverName, "intelisis", "");
mssql_select_db($DB, $conn);
$user = $_SESSION["user"];
if (!$conn) {
die('Something went wrong while connecting to MSSQL');
}
$con1 = "set dateformat dmy";
$con1 = mssql_query($con1);
$con2 = "SET DATEFIRST 7";
$con2 = mssql_query($con2);
$con3 = "SET ANSI_NULLS OFF";
$con3 = mssql_query($con3);
$con4 = "SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED";
$con4 = mssql_query($con4);
$con5 = "SET LOCK_TIMEOUT -1";
$con5 = mssql_query($con5);
$con6 = "SET QUOTED_IDENTIFIER OFF";
$con6 = mssql_query($con6);
$con7 = "set language spanish";
$con7 = mssql_query($con7);
}
示例9: connect
public function connect()
{
if ($this->conn_id && $this->state == self::OPEN) {
mssql_select_db($this->getDatabase(), $this->conn_id);
return true;
}
//TODO preConnect actions should be called from here
$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) {
$this->conn_id = @mssql_pconnect($hostString, $this->getUser(), $this->getPassword(), $flags);
} else {
$this->conn_id = @mssql_connect($hostString, $this->getUser(), $this->getPassword(), $flags);
}
if (!$this->conn_id) {
$this->state = self::CLOSED;
$msg = '[!Database connection error!]: ' . $this->getDatabase() . ' - ' . $this->getErrorMsg();
PhpBURN_Message::output($msg, PhpBURN_Message::ERROR);
return false;
}
//Selecting database
mssql_select_db($this->getDatabase(), $this->conn_id);
$this->state = self::OPEN;
//TODO onConnectSucess actions should be called from here
return true;
}
示例10: Open
function Open($dbType, $connectType = "c", $connect, $username = "", $password = "", $dbName)
{
switch ($dbType) {
case "mssql":
if ($connectType == "c") {
$idCon = mssql_connect($connect, $username, $password);
} else {
$idCon = mssql_pconnect($connect, $username, $password);
}
mssql_select_db($dbName);
break;
case "mysql":
if ($connectType == "c") {
$idCon = @mysql_connect($connect, $username, $password);
} else {
$idCon = @mysql_pconnect($connect, $username, $password);
}
$idCon1 = mysql_select_db($dbName, $idCon);
break;
case "pg":
if ($connectType == "c") {
$idCon = pg_connect($connect . " user=" . $username . " password=" . $password . " dbname=" . $dbName);
} else {
$idCon = pg_pconnect($connect . " user=" . $username . " password=" . $password . " dbname=" . $dbName);
}
break;
default:
$idCon = 0;
break;
}
return $idCon;
}
示例11: Connect
/**
* @return bool
*/
function Connect()
{
//if ($this->_conectionHandle != false) return true;
if (!extension_loaded('mssql')) {
$this->ErrorDesc = 'Can\'t load MsSQL extension.';
setGlobalError($this->ErrorDesc);
$this->_log->WriteLine($this->ErrorDesc);
return false;
}
$ti = getmicrotime();
$this->_conectionHandle = @mssql_connect($this->_host, $this->_user, $this->_password);
$this->_log->WriteLine('>> CONNECT TIME - ' . (getmicrotime() - $ti));
if ($this->_conectionHandle) {
if (strlen($this->_dbName) > 0) {
$dbselect = @mssql_select_db($this->_dbName, $this->_conectionHandle);
if (!$dbselect) {
$this->_setSqlError();
$this->_conectionHandle = $dbselect;
@mssql_close($this->_conectionHandle);
return false;
}
}
return true;
} else {
$this->_setSqlError();
return false;
}
}
示例12: get_web_log
public function get_web_log()
{
//select the database
mssql_select_db($this->dbname, $this->dbcon);
//SQL Select statement
$xml = new XMLHandler(XML_DIR . "web_request_spk.xml");
$sql_from_xml = $xml->getNode("web_log");
$sqlselect = str_replace("FILTER_BY_PROGRAM", "", $sql_from_xml);
//Run the SQL query
$result = mssql_query($sqlselect);
$numfields = mssql_num_fields($result);
$string_result = "";
while ($row = mssql_fetch_row($result)) {
$string_result .= "<tr>";
for ($i = 0; $i < $numfields; $i++) {
if (mssql_field_name($result, $i) == "IP_ADDRESS") {
$ip = explode(":", $row[$i]);
$string_result .= "<td>" . $ip[0] . "</td>";
$string_result .= "<td>" . $ip[1] . "</td>";
} else {
$string_result .= "<td>" . $row[$i] . "</td>";
}
}
$string_result .= "</tr>";
}
return $string_result;
}
示例13: connect
/**
* Make the connection
*
* @return return connection
*/
public function connect()
{
// Check if link already exists
if (is_resource($this->link)) {
return $this->link;
}
// Import the connect variables
extract($this->db_config['connection']);
// Persistent connections enabled?
$connect = $this->db_config['persistent'] == TRUE ? 'mssql_pconnect' : 'mssql_connect';
// Build the connection info
$host = isset($host) ? $host : $socket;
// Windows uses a comma instead of a colon
$port = (isset($port) and is_string($port)) ? (KOHANA_IS_WIN ? ',' : ':') . $port : '';
// Make the connection and select the database
if ($this->link = $connect($host . $port, $user, $pass, TRUE) and mssql_select_db($database, $this->link)) {
/* This is being removed so I can use it, will need to come up with a more elegant workaround in the future...
*
if ($charset = $this->db_config['character_set'])
{
$this->set_charset($charset);
}
*/
// Clear password after successful connect
$this->config['connection']['pass'] = NULL;
return $this->link;
}
return FALSE;
}
示例14: reconnect
function reconnect()
{
global $gbl, $sgbl, $login, $ghtml;
$this->__readserver = 'localhost';
$user = $sgbl->__var_admin_user;
$db = $sgbl->__var_dbf;
$pass = getAdminDbPass();
$readserver = $this->__readserver;
$fdbvar = "__fdb_" . $this->__readserver;
log_log("database_reconnect", "Reconnecting again");
if ($sgbl->__var_database_type === 'mysql') {
$gbl->{$fdbvar} = mysql_connect($readserver, $user, $pass);
mysql_select_db($db);
self::$__database = 'mysql';
} else {
if ($sgbl->__var_database_type === 'mssql') {
//print("$user, $pass <br> \n");
//$gbl->$fdbvar = mssql_connect('\\.\pipe\MSSQL$LXLABS\sql\query');
$gbl->{$fdbvar} = mssql_pconnect("{$readserver},{$sgbl->__var_mssqlport}");
mssql_select_db($db);
self::$__database = 'mssql';
} else {
$gbl->{$fdbvar} = new PDO("sqlite:{$db}");
self::$__database = 'sqlite';
}
}
}
示例15: __construct
function __construct()
{
// Load Configuration for this Module
global $configArray;
$this->hipUrl = $configArray['Catalog']['hipUrl'];
$this->hipProfile = $configArray['Catalog']['hipProfile'];
$this->selfRegProfile = $configArray['Catalog']['selfRegProfile'];
// Connect to database
if (!isset($configArray['Catalog']['useDb']) || $configArray['Catalog']['useDb'] == true) {
try {
if (strcasecmp($configArray['System']['operatingSystem'], 'windows') == 0) {
sybase_min_client_severity(11);
$this->db = @sybase_connect($configArray['Catalog']['database'], $configArray['Catalog']['username'], $configArray['Catalog']['password']);
} else {
$this->db = mssql_connect($configArray['Catalog']['host'] . ':' . $configArray['Catalog']['port'], $configArray['Catalog']['username'], $configArray['Catalog']['password']);
// Select the database
mssql_select_db($configArray['Catalog']['database']);
}
} catch (Exception $e) {
global $logger;
$logger->log("Could not load Horizon database", PEAR_LOG_ERR);
}
} else {
$this->useDb = false;
}
}