function sql_db($sqlserver, $sqluser, $sqlpassword, $database, $persistency = true) { $mtime = microtime(); $mtime = explode(" ", $mtime); $mtime = $mtime[1] + $mtime[0]; $starttime = $mtime; $this->persistency = $persistency; $this->user = $sqluser; $this->password = $sqlpassword; $this->server = $sqlserver; $this->dbname = $database; $this->db_connect_id = $this->persistency ? @mssql_pconnect($this->server, $this->user, $this->password) : @mssql_connect($this->server, $this->user, $this->password); if ($this->db_connect_id && $this->dbname != "") { if (!mssql_select_db($this->dbname, $this->db_connect_id)) { mssql_close($this->db_connect_id); $mtime = microtime(); $mtime = explode(" ", $mtime); $mtime = $mtime[1] + $mtime[0]; $endtime = $mtime; $this->sql_time += $endtime - $starttime; return false; } } $mtime = microtime(); $mtime = explode(" ", $mtime); $mtime = $mtime[1] + $mtime[0]; $endtime = $mtime; $this->sql_time += $endtime - $starttime; return $this->db_connect_id; }
/** * Abra a conexão com o banco de dados MSSQL * * <code> * $mssqlHandle = dbOpen_MSSQL("MSSQL", "database", "user", "password"); * </code> * * @param string $dbHost string de conexão com o banco de dados * @param string $dbDatabase[optional] string database utilizado * @param string $dbUser[optional] nome do usuário * @param string $dbPassword[optional] senha do usuário * * @return array com o handleId e o nome do driver * * @since Versão 1.0 */ function dbOpen_MSSQL(&$dbHandle) { $debugBackTrace = debug_backtrace(); $debugFile = basename($debugBackTrace[1]["file"]); $debugFunction = $debugBackTrace[1]["function"]; $dbDriver = $dbHandle[dbHandleDriver]; if (!function_exists("mssql_connect")) { echo "<span style=\"text-align: left;\"><pre><b>{$dbDriver} - {$debugFile} - {$debugFunction}() - Connect</b>:" . "<br />extension=<b>php_mssql.dll</b> is not loaded"; echo "<hr />" . debugBackTrace(); echo "</pre></span>"; die; } $dbHost = $dbHandle[dbHandleHost]; $dbDatabase = $dbHandle[dbHandleDatabase]; $dbUser = $dbHandle[dbHandleUser]; $dbPassword = $dbHandle[dbHandlePassword]; // @TODO Incluir tratamento para ver se o driver está carregado if (!($mssqlConn = @mssql_connect($dbHost, $dbUser, $dbPassword))) { echo "<span style=\"text-align: left;\"><pre><b>{$dbDriver} - {$debugFile} - {$debugFunction}() - Connect</b>:" . "<br /><b>Connection</b>: " . $dbHost . "<br /><b>Database</b>: " . $dbDatabase . "<br /><b>Message</b>: [" . mssql_get_last_message() . "]"; echo "<hr />" . debugBackTrace(); echo "</pre></span>"; die; } if (!@mssql_select_db($dbDatabase, $mssqlConn)) { echo "<span style=\"text-align: left;\"><pre><b>{$dbDriver} - {$debugFile} - {$debugFunction}() - SelectDB</b>:" . "<br /><b>Connection</b>: " . $dbHost . "<br /><b>Database</b>: " . $dbDatabase . "<br /><b>Message</b>: [" . mssql_get_last_message() . "]"; echo "<hr />" . debugBackTrace(); echo "</pre></span>"; die; } return $mssqlConn; }
/** * Connect * * @param bool reconnect default FALSE * @return bool success * @throws rdbms.SQLConnectException */ public function connect($reconnect = false) { if (is_resource($this->handle)) { return true; } // Already connected if (!$reconnect && false === $this->handle) { return false; } // Previously failed connecting $this->_obs && $this->notifyObservers(new \rdbms\DBEvent(\rdbms\DBEvent::CONNECT, $reconnect)); if ($this->flags & DB_PERSISTENT) { $this->handle = mssql_pconnect($this->dsn->getHost(), $this->dsn->getUser(), $this->dsn->getPassword()); } else { $this->handle = mssql_connect($this->dsn->getHost(), $this->dsn->getUser(), $this->dsn->getPassword()); } if (!is_resource($this->handle)) { $e = new \rdbms\SQLConnectException(trim(mssql_get_last_message()), $this->dsn); \xp::gc(__FILE__); throw $e; } \xp::gc(__FILE__); $this->_obs && $this->notifyObservers(new \rdbms\DBEvent(\rdbms\DBEvent::CONNECTED, $reconnect)); return parent::connect(); }
/** * Start Connection Server * Connect to Microsoft SQL Server * * @return void */ public function StartConnection() { if (!extension_loaded("mssql")) { if (!extension_loaded("sqlsrv")) { return $this->results['Connect'] = "NO_PHP_EXTENSION"; } else { $this->useSqlsrv = TRUE; } } if (!$this->settings['hostport']) { $this->settings['hostport'] = 1433; } $new_link = count($this->connections) > 0; $port = (strtoupper(substr(PHP_OS, 0, 3)) === "WIN" ? "," : ":") . $this->settings['hostport']; if (!$this->useSqlsrv) { if ($this->settings['persistent']) { $this->connections[$this->id] = mssql_pconnect($this->settings['hostname'] . $port, $this->settings['username'], $this->settings['password'], $new_link); } else { $this->connections[$this->id] = mssql_connect($this->settings['hostname'] . $port, $this->settings['username'], $this->settings['password'], $new_link); } } if (!$this->connections[$this->id]) { return $this->results['Connect'] = "CONNECTION_FAILED"; } if (!$this->SelectDataBase($this->settings['database'], $this->id)) { return $this->results['Connect'] = "DATABASE_FAILED"; } $this->id++; $this->connected = TRUE; $this->currentLink = $this->id - 1; return $this->results['Connect'] = "CONNECTED"; }
public function __construct($hostname, $userid, $password) { $this->hostname = $hostname; $this->userid = $userid; $this->password = $password; $this->connection = mssql_connect($hostname, $userid, $password, false); }
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); }
/** * {@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; }
function connect() { $this->last_errno = 0; $this->last_error = ''; if (isset($this->mssql)) { $this->dbh = @mssql_connect($this->dbhost, $this->dbuser, $this->dbpassword, true); } else { $this->dbh = @mysql_connect($this->dbhost, $this->dbuser, $this->dbpassword, true); } if (!$this->dbh) { $this->ready = false; if (isset($this->mssql)) { $this->last_error = mssql_get_last_message(); if (empty($this->last_error)) { $this->last_error = 'Unable to connect to mssql: ' . $this->dbhost; } $this->last_errno = 1; } else { $this->last_error = mysql_error(); $this->last_errno = mysql_errno(); } return false; } $this->ready = true; $this->real_escape = true; $this->select($this->dbname, $this->dbh); }
/** * 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']); } }
/** * 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(''); }
/** * 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"); } }
function getProductos() { $myServer = "172.30.5.49"; $myUser = "******"; $myPass = "******"; $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 . '}'; } }
/** * Connect to server */ function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false, $new_link = false) { $this->persistency = $persistency; $this->user = $sqluser; $this->server = $sqlserver . (($port) ? ':' . $port : ''); $this->dbname = $database; @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(''); }
private function getDbConnect($address, $account, $pwd, $name) { if (DB_TYPE == 'mssql') { return mssql_connect($address, $account, $pwd); } if (DB_TYPE == 'sqlsrv') { if (defined('DBITPro_Dev')) { $connectionInfo = array("UID" => $account, "PWD" => $pwd, "Database" => $name); } else { $connectionInfo = array("UID" => $account, "PWD" => $pwd, "Database" => $name); } $conn = sqlsrv_connect($address, $connectionInfo); if (false === $conn) { echo "Could not connect.\n"; die(print_r(sqlsrv_errors(), true)); } return $conn; } if (DB_TYPE == 'mysql') { $conn = mysql_connect($address, $account, $pwd); if (false === $conn) { echo "Could not connect.\n"; die(print_r(mysql_errors(), true)); } return $conn; } }
/** * Non-persistent database connection * * @access private called by the base class * @return resource */ function db_connect() { if ($this->port != '') { $this->hostname .= ',' . $this->port; } return @mssql_connect($this->hostname, $this->username, $this->password); }
function __construct($server = DB_HOST, $username = DB_USER, $password = DB_PASSWORD, $database_name = DB_NAME, $table_prefix = DB_TABLE_PREFIX, $db_type = DB_TYPE_MYSQL) { $this->db_type = $db_type; switch ($this->db_type) { case DB_TYPE_MYSQL: $this->link = mysql_connect($server, $username, $password, true); if (!$this->link) { die("Cannot connect to DB"); } if (!mysql_select_db($database_name, $this->link)) { die("Cannot select db"); } break; case DB_TYPE_MYSQLI: $this->link = mysqli_connect($server, $username, $password, $database_name); if (!$this->link) { die("Cannot connect to DB"); } break; case DB_TYPE_MSSQL: $this->link = mssql_connect($server, $username, $password, true); if (!$this->link) { die("Cannot connect to DB"); } if (!mssql_select_db($database_name, $this->link)) { die("Cannot select db"); } break; } $this->table_prefix = $table_prefix; }
/** * Database object constructor * @param string Database host * @param string Database user name * @param string Database user password * @param string Database name * @param string Common prefix for all tables */ function __construct($options) { //var_dump_pre($options); $host = array_key_exists('host', $options) ? $options['host'] : 'localhost'; $user = array_key_exists('user', $options) ? $options['user'] : ''; $password = array_key_exists('password', $options) ? $options['password'] : ''; $database = array_key_exists('database', $options) ? $options['database'] : ''; $prefix = array_key_exists('prefix', $options) ? $options['prefix'] : 'jos_'; $select = array_key_exists('select', $options) ? $options['select'] : true; // perform a number of fatality checks, then return gracefully if (!function_exists('mssql_connect')) { $this->_errorNum = 1; $this->_errorMsg = 'The MSSQL adapter "mssql" is not available.'; return; } // connect to the server if (!($this->_resource = @mssql_connect($host, $user, $password, true))) { $this->_errorNum = 2; $this->_errorMsg = 'Could not connect to MSSQL: ' . mssql_get_last_message(); print_r($this->_resource); return; } else { $this->connected = true; } // finalize initializations parent::__construct($options); // select the database if ($select) { $this->select('[' . $database . ']'); } }
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="******" password="******" dbname=" . $dbName); } else { $idCon = pg_pconnect($connect . " user="******" password="******" dbname=" . $dbName); } break; default: $idCon = 0; break; } return $idCon; }
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; } }
/** * @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; } }
function dbquery_func_old($connection_info, $query, $debug = "off") { if ($connection_info['db_type'] == "mysql") { mysql_connect($connection_info['db_host'] . ":" . $connection_info['db_port'], $connection_info['username'], $connection_info['password']) or die("Unable to connect to " . $connection_info['db_host']); mysql_select_db($connection_info['db_name']) or die("Unable to select database " . $connection_info['db_name']); $return = mysql_query($query); if ($debug == "on") { $merror = mysql_error(); if (!empty($merror)) { print "MySQL Error:<br />" . $merror . "<p />Query<br />: " . $query . "<br />"; } print "Number of rows returned: " . mysql_num_rows($return) . "<br />"; } } else { if ($connection_info['db_type'] == "mssql") { mssql_connect($connection_info['db_host'] . "," . $connection_info['db_port'], $connection_info['username'], $connection_info['password']) or die("Unable to connect to " . $connection_info['db_host'] . "<br />" . $query); mssql_select_db($connection_info['db_name']) or die("Unable to select database " . $connection_info['db_name']); $return = mssql_query($query); if ($debug == "on") { $merror = mssql_get_last_message(); if (!empty($merror)) { print "MySQL Error: " . $merror . "<br />Query" . $query . "<br />"; } print "Number of rows returned: " . mssql_num_rows($result) . "<br />"; } } } return $return; }
/** * digunakan untuk koneksi ke database * @param param array (host,dbname,user,password) * @return void */ public function connectDB($param) { $this->conn = @mssql_connect($param['host'], $param['user'], $param['password']); if ($this->conn) { mssql_select_db($param['dbname'], $this->conn); } }
/** db::connect * Connects to a MySQL server, then selects the database. * This function will halt execution if it fails. * @param Server URL * @param SQL User name * @param SQL Password * @param Database to select from */ function connect($dbURL, $dbUserName, $dbPassword, $dbDatabase) { // Don't connect if we don't specify a URL if (!$dbURL) { return false; } // Attempt connection to SQl database if ($this->mode == 'mysql') { $this->link = mysql_connect($dbURL, $dbUserName, $dbPassword); } if ($this->mode == 'mssql') { $this->link = mssql_connect($dbURL, $dbUserName, $dbPassword); } // Check for link failure, Stop execution if connection fails if (!$this->link) { die("Could not connect to database at " . $dbURL . ".<br>Reason: " . mysql_error()); } // Try to select the database if ($this->mode == 'mysql') { if (!mysql_select_db($dbDatabase, $this->link)) { die("Failed to select database '" . $dbDatabase . "'<br>Reason: " . mysql_error()); } } if ($this->mode == 'mssql') { if (!mssql_select_db($dbDatabase, $this->link)) { die("Failed to select database \\'" . $dbDatabase . "\\'<br>Reason: " . mysql_error()); } } $this->connected = true; }
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; }
public function __construct($param) { if (!$param['db_host'] || !$param['db_user'] || !$param['db_pass'] || !$param['db_name']) { jlog('mssql', 'db name or host or user or password is empty'); } if ($param['db_port']) { $pd = defined('PHP_OS') && substr(PHP_OS, 0, 3) == 'WIN' ? ',' : ':'; $param['db_host'] .= $pd . $param['db_port']; } if (!function_exists('mssql_connect')) { jlog('mssql', 'function mssql_connect is invalid'); } @ini_set('mssql.charset', $param['db_charset']); @ini_set('mssql.textlimit', 2147483647); @ini_set('mssql.textsize', 2147483647); $this->link = mssql_connect($param['db_host'], $param['db_user'], $param['db_pass']); if (!$this->link) { jlog('mssql', 'connect is invalid<br />error message: ' . $this->error()); } if (!mssql_select_db($param['db_name'], $this->link)) { mssql_close($this->link); jlog('mssql', 'db name select is invalid'); } return true; }
/** * connect to the database */ function connect() { $this->link = mssql_connect($this->dbconfig['host'], $this->dbconfig['login'], $this->dbconfig['password'], true); if (!$this->link) { throw new DatabaseConnectException("Could not connect to server " . $this->dbconfig['host']); } if (!empty($this->dbconfig['database'])) { $db = $this->dbconfig['database']; if ($db[0] != '[') { $db = '[' . $db . ']'; } if (!mssql_select_db($db, $this->link)) { throw new DatabaseConnectException("Could not select Database " . $this->dbconfig['database']); } } if (!empty($this->dbconfig['encoding'])) { $this->setEncoding($this->dbconfig['encoding']); } //freetds hack: freetds does not offer this function :( if (!function_exists("mssql_next_result")) { function mssql_next_result($res = null) { return false; } } }
function connect($dsn = false) { $this->lasterr = null; $this->lasterrcode = null; if ($this->conn && $dsn == false) { return true; } if (!$dsn) { $dsn = $this->dsn; } else { $this->dsn = $dsn; } if (isset($dsn['port']) && $dsn['port'] != '') { $host = $dsn['host'] . ':' . $dsn['port']; } else { $host = $dsn['host']; } if (!isset($dsn['login'])) { $dsn['login'] = ''; } if (!isset($dsn['password'])) { $dsn['password'] = ''; } $this->conn = mssql_connect($host, $dsn['login'], $dsn['password']); if (!$this->conn) { FLEA::loadClass('FLEA_Db_Exception_SqlQuery'); return __THROW(new FLEA_Db_Exception_SqlQuery("mssql_connect('{$host}', '{$dsn['login']}') failed!", $this->_error(), $this->_errno())); } if (!mssql_select_db($dsn['database'], $this->conn)) { FLEA::loadClass('FLEA_Db_Exception_SqlQuery'); return __THROW(new FLEA_Db_Exception_SqlQuery("SELECT DATABASE: '{$dsn['database']}' FAILED!", $this->_error($this->conn), $this->_errno($this->conn))); } return true; }
function comprobar($b) { $con = mssql_connect('192.168.1.4', 'APLICACIONES', 'APLICACIONES'); mssql_select_db('[010BDCOMUN]', $con); $sql = mssql_query("SELECT ACODIGO,ADESCRI,\r\n(ISNULL(STSKDIS,0)-SUM(ISNULL(CANT_PEND,0)))AS STOCK\r\nFROM [010BDCOMUN].DBO.MAEART AS M LEFT JOIN [010BDCOMUN].DBO.STKART AS S ON\r\nM.ACODIGO=S.STCODIGO AND STALMA='01' LEFT JOIN [022BDCOMUN].DBO.RESERVA_DET AS D ON\r\nS.STCODIGO=D.CODIGO \r\n\r\nWHERE AESTADO='V' AND AFSTOCK='S' AND ACODIGO='" . $b . "'\r\n\r\nGROUP BY ACODIGO,ADESCRI,STSKDIS ", $con); $contar = mssql_fetch_array($sql); echo "STOCK:" . round($contar['STOCK'], 3); }
public function connect() { if (self::$connection === null) { self::$connection = mssql_connect(DB_HOST, DB_USER, DB_PWD); mssql_select_db(DB_DATABASE, self::$connection); } return self::$connection; }
function SQLServer($dbuser, $dbpassword, $dbname, $dbhost) { $this->dbh = @mssql_connect($dbhost, $dbuser, $dbpassword); if (!$this->dbh) { $this->print_error("<ol><b>错误:不能建立数据库连接!</b><li>是否输入了正确的用户名和密码?<li>是否输入了正确的主机名?<li>数据库服务器是否运行?</ol>"); } $this->select($dbname); }