/// <inheritDoc /> public void __construct(string dsn, string username = null, string password = null, PhpArray options = null) { this.SetDefaultAttributes(); string driver; ReadOnlySpan <char> connstring; int doublecolon = dsn.IndexOf(':'); if (doublecolon >= 0) { driver = dsn.Remove(doublecolon); connstring = dsn.AsSpan(doublecolon + 1); } else { // Alias mode throw new NotImplementedException("PDO DSN alias not implemented"); // replace DSN alias with value } if (driver == "uri") // TODO: move to a driver "UriDriver" { // Uri mode if (Uri.TryCreate(connstring.ToString(), UriKind.Absolute, out var uri)) { if (uri.Scheme.Equals("file", StringComparison.Ordinal)) { throw new NotImplementedException("PDO uri DSN not implemented"); //return } else { throw new PDOException("PDO DSN as URI does not support other schemes than 'file'"); } } else { throw new PDOException("Invalid uri in DSN"); } } // DSN mode this.m_driver = PDOEngine.TryGetDriver(driver) ?? throw new PDOException($"Driver '{driver}' not found"); // TODO: resources try { this.m_con = this.m_driver.OpenConnection(connstring, username, password, options); } catch (Exception e) { throw new PDOException(e.Message); } this.m_attributes[PDO_ATTR.ATTR_SERVER_VERSION] = (PhpValue)this.m_con.ServerVersion; this.m_attributes[PDO_ATTR.ATTR_DRIVER_NAME] = (PhpValue)this.m_driver.Name; this.m_attributes[PDO_ATTR.ATTR_CLIENT_VERSION] = (PhpValue)this.m_driver.ClientVersion; }
/// <summary> /// Registers the driver. /// </summary> public static void RegisterDriver(IPDODriver driver) { lock (s_drivers) { if (!s_drivers.ContainsKey(driver.Name)) { s_drivers.Add(driver.Name, driver); } } }
/// <inheritDoc /> public void __construct(string dsn, string username = null, string password = null, PhpArray options = null) { this.SetDefaultAttributes(); string[] items = dsn.Split(new[] { ':' }, 2); if (items[0].Equals("uri", StringComparison.Ordinal)) { //Uri mode Uri uri; if (Uri.TryCreate(items[1], UriKind.Absolute, out uri)) { if (uri.Scheme.Equals("file", StringComparison.Ordinal)) { throw new NotImplementedException("PDO uri DSN not implemented"); //return } else { throw new PDOException("PDO DSN as URI does not support other schemes than 'file'"); } } else { throw new PDOException("Invalid uri in DSN"); } } if (items.Length == 1) { //Alias mode throw new NotImplementedException("PDO DSN alias not implemented"); //replace DSN alias with value } //DSN mode this.m_driver = PDOEngine.GetDriver(items[0]); if (this.m_driver == null) { throw new PDOException(string.Format("Driver '{0}' not found", items[0])); } this.m_extensionMethods = this.m_driver.GetPDObjectExtensionMethods(); if (this.m_driver.Name == "mysql") { items[1] = PDOMySQLWrapper.convertDSN(items[1]); } this.m_con = this.m_driver.OpenConnection(items[1], username, password, options); this.m_attributes.Set(PDO_ATTR.ATTR_SERVER_VERSION, (PhpValue)this.m_con.ServerVersion); this.m_attributes.Set(PDO_ATTR.ATTR_DRIVER_NAME, (PhpValue)this.m_driver.Name); this.m_attributes.Set(PDO_ATTR.ATTR_CLIENT_VERSION, (PhpValue)this.m_driver.ClientVersion); }