Gets last error
@param  string $db Dbname
@param  callable $cb Callback called when response received
@param  array $params Parameters.
@param  Connection $conn Connection. Optional
@callback $cb ( )
@return void
173547
public function lastError($db, $cb, $params = [], $conn = null)
    {
        $e = explode('.', $db, 2);
        $params['getlasterror'] = 1;
        $cb = CallbackWrapper::wrap($cb);
        try {
            $this->request(
                self::OP_QUERY,
                pack('V', 0) . $e[0] . '.$cmd' . "\x00"
                . pack('VV', 0, -1) . bson_encode($params),
                true,
                $conn,
                function ($conn, $reqId = null) use ($db, $cb) {
                    if (!$conn) {
                        !$cb || $cb(['$err' => 'Connection error.']);
                        return;
                    }
                    $conn->requests[$reqId] = [$db, $cb, true];
                }
            );
        } catch (\MongoException $e) {
            Daemon::log('MongoClient exception: ' . $e->getMessage() . ': ' . $e->getTraceAsString());
            if ($cb !== null) {
                $cb(['$err' => $e->getMessage()]);
            }
        }
    }
1296199
public function getLastError($attribute = null)
    {
        if (empty($this->errors)) {
            return null;
        }
        if (isset($attribute)) {
            if (isset($this->errors[$attribute])) {
                return end($this->errors[$attribute]);
            }
            return null;
        }
        $error = end($this->errors);
        if (is_array($error)) {
            return end($error);
        }
        return $error;
    }
964872
function (conn) {
            if (!this.__validateConnectionCB) {
                var ret = new Promise();
                ret.callback(true);
                return ret;
            } else {
                return this.__validateConnectionCB(conn);
            }
        }
79424
function _pconnect($argDSN, $argUsername, $argPassword, $argDatabasename)
	{
	global $php_errormsg;

		if (!function_exists('odbc_connect')) return null;

		if (isset($php_errormsg)) $php_errormsg = '';
		$this->_errorMsg = isset($php_errormsg) ? $php_errormsg : '';
		if ($this->debug && $argDatabasename) {
			ADOConnection::outp("For odbc PConnect(), $argDatabasename is not used. Place dsn in 1st parameter.");
		}
	//	print "dsn=$argDSN u=$argUsername p=$argPassword<br>"; flush();
		if ($this->curmode === false) $this->_connectionID = odbc_connect($argDSN,$argUsername,$argPassword);
		else $this->_connectionID = odbc_pconnect($argDSN,$argUsername,$argPassword,$this->curmode);

		$this->_errorMsg = isset($php_errormsg) ? $php_errormsg : '';
		if ($this->_connectionID && $this->autoRollback) @odbc_rollback($this->_connectionID);
		if (isset($this->connectStmt)) $this->Execute($this->connectStmt);

		return $this->_connectionID != false;
	}
219584
function query($sql)
    {
        if (true == Config::get('sql_log')) {
            wlog('SQL-Log', $sql);
        }

        if (true == ($rs = $this->db->query($sql))) {
            $GLOBALS['__$DB_QUERY_COUNT']++;
            return $rs;
        } else if($this->db->errno == 2006 || $this->db->errno == 2013) {
            // Catch database pool long running
            // 2013 Lost connection to MySQL server during query
            // 2006 MySQL server has gone away
            $this->reconnect();

            $GLOBALS['__$DB_QUERY_COUNT']++;
            return $this->db->query($sql);
        } else {
            \throw_error('DB_ERROR: ' . $this->db->error . "\nRAW_SQL: " . $sql, $this->db->errno);
        }
    }
437200
function checkConnection(options, cb) {
    if (count < options.attempts) {
        connectServer(options, callback);
    } else {
        var avg = results.reduce(function(prev, curr) { return prev + curr.time; }, 0);
        var max = results.reduce(function(prev, curr) { return (prev > curr.time) ? prev : curr.time; }, results[0].time);
        var min = results.reduce(function(prev, curr) { return (prev < curr.time) ? prev : curr.time; }, results[0].time);

        avg = avg / results.length;
        var out = {
            address:  options.address,
            port:     options.port,
            attempts: options.attempts,
            avg:      avg,
            max:      max,
            min:      min,
            results:  results
        };

        cb(undefined, out);
    }
}
138639
public function getLastErrorForMethod($_methoName)
    {
        return (is_array($this->lastError) && array_key_exists($_methoName,$this->lastError))?$this->lastError[$_methoName]:null;
    }
394651
private function check_errors() {
 	 	switch($this->db['phptype']) {
 	 		case "sqlite":
				if ($this->sqlite_version == 3) {
					$this->errno = $this->conn->lastErrorCode();
					$this->error = $this->conn->lastErrorMsg();
				} else {
					$this->errno = sqlite_last_error($this->conn);
					$this->error = sqlite_error_string($this->errno);
				}
 	 			break;
 	 		case "mysql":
 	 			$this->errno = mysql_errno($this->conn);
 	 			$this->error = mysql_error($this->conn);
 	 			break;
 	 		case "mysqli":
				if (mysqli_connect_error()) {
					die('Connect Error: ' . mysqli_connect_error());
				}
 	 			$this->errno = mysqli_errno($this->conn);
 	 			$this->error = mysqli_error($this->conn);
 	 			break;
 	 	}

 	}
520184
public function query($q, $cb = null)
    {
        if ($this->finished) {
            throw new ConnectionFinished;
        }
        return $this->command(Pool::COM_QUERY, $q, $cb);
    }
192146
protected void checkForBatchSupport(Connection conn)
    {
        if (!m_batchUpdatesChecked)
        {
            DatabaseMetaData meta;
            try
            {
                meta = conn.getMetaData();
                m_supportsBatchUpdates = meta.supportsBatchUpdates();
            }
            catch (Throwable th)
            {
                log.info("Batch support check failed", th);
                m_supportsBatchUpdates = false;
            }
            finally
            {
                m_batchUpdatesChecked = true;
            }
        }
    }
1278727
public static function last( $table, $key = null, $handler = null ) 
	{
		return Query::select( $table )->last( $key, $handler );
	}
878118
function getQueryStatement(PDO $conn = null) {
		if (0 === count($this->conds)) {
			return null;
		}

		$stmnt = new QueryStatement($conn);

		$is_first = true;
		$is_second = false;
		foreach ($this->conds as &$cond) {
			$cond_stmnt = null;

			// avoid call_user_func_array for better stack traces
			switch (count($cond[1])) {
				case 1:
					$cond_stmnt = self::processCondition($cond[1][0]);
					break;
				case 2:
					$cond_stmnt = self::processCondition($cond[1][0], $cond[1][1]);
					break;
				case 3:
					$cond_stmnt = self::processCondition($cond[1][0], $cond[1][1], $cond[1][2]);
					break;
				case 4:
					$cond_stmnt = self::processCondition($cond[1][0], $cond[1][1], $cond[1][2], $cond[1][3]);
					break;
			}

			if (null === $cond_stmnt) {
				continue;
			}

			if ($is_first) {
				$sep = '';
				$is_first = false;
				$is_second = true;
			} else {
				$sep = (($is_second && 'OR' === $this->conds[0][0]) ? 'OR' : $cond[0]) . ' ';
				$is_second = false;
			}

			$stmnt->string .= "\n\t$sep" . $cond_stmnt->string;
			$stmnt->addParams($cond_stmnt->params);
			$stmnt->addIdentifiers($cond_stmnt->identifiers);
		}
		return $stmnt;
	}
1373723
public static void closeConnection(Connection conn){
		if (conn != null) {
			try {
				conn.close();
			} catch (Exception e) {
				log.warn("Exception when closing database connection.", e);
			}
		}
	}
1191409
public function get_last_error() {
        $retErrors = sqlsrv_errors(SQLSRV_ERR_ALL);
        $errorMessage = 'No errors found';

        if ($retErrors != null) {
            $errorMessage = '';

            foreach ($retErrors as $arrError) {
                $errorMessage .= "SQLState: ".$arrError['SQLSTATE']."<br>\n";
                $errorMessage .= "Error Code: ".$arrError['code']."<br>\n";
                $errorMessage .= "Message: ".$arrError['message']."<br>\n";
            }
        }

        return $errorMessage;
    }
945588
public static function closeDbConnection()
    {
        if (isset(self::$dbLink)) {
            $dbConn = self::$dbLink;
            $dbConn->close();
            self::$dbLink = null;
        }
        
        return null;
    }
860070
function(callback) {
      if (this.mysql) {
        var db = this;
        this.ready = false;
        this.mysql.end(function(error) {
          callback.call(db,error);
          if (error) {
            db.emit("error",error);
          } else {
            db.emit("close");
          }
        });
      } else {
        callback.call(this);
      }
      return this;
    }
787395
function doCount(PDO $conn = null) {
		$q = clone $this;

		if (!$q->getTable()) {
			throw new RuntimeException('No table specified.');
		}

		$q->setAction(self::ACTION_COUNT);
		return (int) $q->getQuery($conn)->bindAndExecute()->fetchColumn();
	}