/** +---------------------------------------------------------- * 连接数据库方法 +---------------------------------------------------------- * @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]; }
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; } }
/** * 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(''); }
/** * {@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; }
/** * 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']); } }
/** * 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 . '}'; } }
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); }
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; }
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; }
/** * @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; } }
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; }
/** * 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; }
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'; } } }
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; } }
/** * 连接数据库方法 * @access public */ public function connect($config = '', $linkNum = 0) { if (!isset($this->linkID[$linkNum])) { if (empty($config)) { $config = $this->config; } $pconnect = !empty($config['params']['persist']) ? $config['params']['persist'] : $this->pconnect; $conn = $pconnect ? 'mssql_pconnect' : 'mssql_connect'; // 处理不带端口号的socket连接情况 $sepr = IS_WIN ? ',' : ':'; $host = $config['hostname'] . ($config['hostport'] ? $sepr . "{$config['hostport']}" : ''); $this->linkID[$linkNum] = $conn($host, $config['username'], $config['password']); if (!$this->linkID[$linkNum]) { throw_exception("Couldn't connect to SQL Server on {$host}"); } if (!empty($config['database']) && !mssql_select_db($config['database'], $this->linkID[$linkNum])) { throw_exception("Couldn't open database '" . $config['database']); } // 标记连接成功 $this->connected = true; //注销数据库安全信息 if (1 != C('DB_DEPLOY_TYPE')) { unset($this->config); } } return $this->linkID[$linkNum]; }
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; }
/** 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; }
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; }
/** * 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(''); }
/** * 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); } }
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; } } }
/** * 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; }
function xcopy($mssql, $mysql, $db, $table, $sql) { $start = microtime(true); mysqli_select_db($mysql, $db); mssql_select_db($db, $mssql); $result = mssql_query($sql, $mssql, 20000); if ($result === false) { die("Error creating sync data\n"); } $s = 0; $r = mssql_num_rows($result); $name_count = mssql_num_fields($result); $name_list = ""; $update_list = ""; $value_list = ""; $sql = ""; $radix = 0; for ($i = 0; $i < $name_count; $i++) { $x = strtolower(mssql_field_name($result, $i)); $name_list .= "{$x},"; if ($x != "dex_row_id") { $update_list .= "{$x} = values({$x}),"; } } $name_list = rtrim($name_list, ","); $update_list = rtrim($update_list, ","); do { while ($row = mssql_fetch_row($result)) { for ($i = 0; $i < $name_count; $i++) { $value_list .= "'" . str_replace("'", "''", trim($row[$i])) . "',"; } $value_list = rtrim($value_list, ","); $radix++; $sql .= "\n({$value_list}),"; $value_list = ""; if ($radix > 2000) { $sql = trim($sql, ","); $sql = "insert into {$table} ({$name_list}) values {$sql} on duplicate key update {$update_list};"; $rset = mysqli_query($mysql, $sql); if ($rset === false) { die("Error inserting mysql data. \n" . mysqli_error($mysql) . "\n\n{$sql}\n\n"); } $radix = 0; $sql = ""; } $s++; } } while (mssql_fetch_batch($result)); if ($sql != "") { $sql = trim($sql, ","); $sql = "insert into {$table} ({$name_list}) values {$sql} on duplicate key update {$update_list};"; $rset = mysqli_query($mysql, $sql); if ($rset === false) { die("Error inserting mysql data. \n" . mysqli_error($mysql) . "\n\n{$sql}\n\n"); } } $end = microtime(true); $total = $end - $start; echo "imported {$db}.{$table} [ {$s} ] records in {$total} sec.\n"; }
public function db_query($pQuery) { if (count(SqlCommand::$theInstances) > 1) { mssql_select_db($this->mDatabaseName, $this->mLink); } return mssql_query($pQuery, $this->mLink); }
function connect($dsninfo, $persistent = false) { if (!DB::assertExtension('mssql') && !DB::assertExtension('sybase')) { return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND); } $this->dsn = $dsninfo; $user = $dsninfo['username']; $pw = $dsninfo['password']; $dbhost = $dsninfo['hostspec'] ? $dsninfo['hostspec'] : 'localhost'; $connect_function = $persistent ? 'mssql_pconnect' : 'mssql_connect'; if ($dbhost && $user && $pw) { $conn = @$connect_function($dbhost, $user, $pw); } elseif ($dbhost && $user) { $conn = @$connect_function($dbhost, $user); } else { $conn = @$connect_function($dbhost); } if (!$conn) { return $this->raiseError(DB_ERROR_CONNECT_FAILED, null, null, null, mssql_get_last_message()); } if ($dsninfo['database']) { if (!@mssql_select_db($dsninfo['database'], $conn)) { return $this->raiseError(DB_ERROR_NODBSELECTED, null, null, null, mssql_get_last_message()); } } $this->connection = $conn; return DB_OK; }
public function get_userinfo($userid, $password) { //select the database mssql_select_db($this->dbname, $this->dbcon); //SQL Select statement $sqlselect = "SELECT userid,password,userright,ws,ws_name,location,fullname,gender,position,member_since,avatar FROM pospass WITH (NOLOCK) WHERE userid ='" . $userid . "';"; //Run the SQL query $sqlquery = mssql_query($sqlselect); $string_result = '{"uservalidation":"false"}'; //$login = new Blowfish(); //$encpassword = $login->genpwd($password); $encpassword = $this->encryptIt($password); while ($result = mssql_fetch_array($sqlquery)) { //$verify = $login->verify_hash($password, $result["password"]); if ($encpassword == $result["password"]) { $xml = new XMLHandler(LOCAL_DIR . "/etc/greenSys.config.xml"); $_SESSION["activedb"] = (string) $xml->Child("locationmapping", $result["location"]); $_SESSION["user-id"] = (string) $userid; $_SESSION["user-ws"] = (string) $result["ws"]; $_SESSION["ws-name"] = (string) $result["ws_name"]; $_SESSION["user-fullname"] = (string) $result["fullname"]; $_SESSION["user-gender"] = (string) $result["gender"]; $_SESSION["user-position"] = (string) $result["position"]; $_SESSION["user-member_since"] = (string) $result["member_since"]; $_SESSION["user-avatar"] = (string) $result["avatar"]; //session_write_close(); //setcookie("user-id",(string)$userid, time()+3600*24); $string_result = '{"uservalidation":"true","fullname":"' . $result["fullname"] . '","gender":"' . $result["gender"] . '","position":"' . $result["position"] . '","member_since":"' . $result["member_since"] . '","avatar":"' . $result["avatar"] . '"}'; } } return $string_result; }
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; }
/** * Connect to the database. * * @throws <b>DatabaseException</b> If a connection could not be created. */ public function connect() { // determine how to get our $method = $this->getParameter('method', 'normal'); switch ($method) { case 'normal': // get parameters normally $database = $this->getParameter('database'); $host = $this->getParameter('host', 'localhost'); $password = $this->getParameter('password'); $user = $this->getParameter('user'); break; case 'server': // construct a connection string from existing $_SERVER values // and extract them to local scope $parameters =& $this->loadParameters($_SERVER); extract($parameters); break; case 'env': // construct a connection string from existing $_ENV values // and extract them to local scope $string =& $this->loadParameters($_ENV); extract($parameters); break; default: // who knows what the user wants... $error = 'Invalid MSSQLDatabase parameter retrieval method ' . '"%s"'; $error = sprintf($error, $method); throw new DatabaseException($error); } // let's see if we need a persistent connection $persistent = $this->getParameter('persistent', false); $connect = $persistent ? 'mssql_pconnect' : 'mssql_connect'; if ($password == null) { if ($user == null) { $this->connection = @$connect($host); } else { $this->connection = @$connect($host, $user); } } else { $this->connection = @$connect($host, $user, $password); } // make sure the connection went through if ($this->connection === false) { // the connection's foobar' $error = 'Failed to create a MSSQLDatabase connection'; throw new DatabaseException($error); } // select our database if ($database != null && !@mssql_select_db($database, $this->connection)) { // can't select the database $error = 'Failed to select MSSQLDatabase "%s"'; $error = sprintf($error, $database); throw new DatabaseException($error); } // since we're not an abstraction layer, we copy the connection // to the resource $this->resource =& $this->connection; }