Exemplo n.º 1
0
 public MySqlConnectionResource(MySqlConnectionManager manager, IDbConnection connection)
     : base(connection.ConnectionString, ResourceName)
 {
     _manager    = manager;
     _connection = connection;
     _leaveopen  = true;
 }
Exemplo n.º 2
0
 /// <summary>
 /// Creates a connection resource using an existing <see cref="IDbConnection"/> instance.
 /// </summary>
 /// <exception cref="ArgumentNullException">Provided instance is <c>null</c>.</exception>
 public static PhpResource mysql_connect(Context ctx, IDbConnection dbconnection /*, bool leaveOpen*/)
 {
     // create connection resource and
     // register it in the list of active connections
     return(MySqlConnectionManager
            .GetInstance(ctx)
            .CreateConnection(dbconnection));
 }
Exemplo n.º 3
0
        public static PhpResource mysql_connect(Context ctx, string server = null, string username = null, string password = null, bool new_link = false, int client_flags = 0)
        {
            var config = ctx.Configuration.Get <MySqlConfiguration>();

            Debug.Assert(config != null);

            var connection_string = BuildConnectionString(config, server, username, password, (ConnectFlags)client_flags);

            bool success;
            var  connection = MySqlConnectionManager.GetInstance(ctx)
                              .CreateConnection(connection_string, new_link, -1, out success);

            if (success)
            {
            }
            else
            {
                connection = null;
            }

            //
            return(connection);
        }
Exemplo n.º 4
0
        public static PhpResource mysql_connect(Context ctx, string server = null, string username = null, string password = null, bool new_link = false, ConnectFlags client_flags = ConnectFlags.None)
        {
            var config = ctx.Configuration.Get <MySqlConfiguration>();

            Debug.Assert(config != null);

            var connection_string = config.ConnectionString ?? BuildConnectionString(config, ref server, config.Port, username, password, client_flags).ToString();

            var connection = MySqlConnectionManager
                             .GetInstance(ctx)
                             .CreateConnection(connection_string, new_link, -1, out var success);

            if (success)
            {
                connection.Server = server;
            }
            else
            {
                connection = null;
            }

            //
            return(connection);
        }
Exemplo n.º 5
0
 public MySqlConnectionResource(MySqlConnectionManager manager, string connectionString)
     : base(manager.Context, connectionString, "mysql connection")
 {
     _manager    = manager;
     _connection = new MySqlConnection(this.ConnectionString);
 }
Exemplo n.º 6
0
 /// <summary>
 /// Gets last active connection.
 /// </summary>
 static MySqlConnectionResource LastConnection(Context ctx) => ctx != null?MySqlConnectionManager.GetInstance(ctx).GetLastConnection() : null;
Exemplo n.º 7
0
 public MySqlConnectionResource(MySqlConnectionManager manager, string connectionString)
     : base(connectionString, ResourceName)
 {
     _manager    = manager;
     _connection = new MySqlConnection(this.ConnectionString);
 }
Exemplo n.º 8
0
        /// <summary>
        /// Returns <paramref name="link"/> as MySql connection or last opened MySql connection for given <paramref name="ctx"/>.
        /// </summary>
        /// <param name="ctx">Runtime context.</param>
        /// <param name="link">Optional, an existing MySql connection resource.</param>
        /// <returns>MySql connection resource or <c>null</c> if there is no connection.</returns>
        public static ConnectionResource ValidConnection(Context ctx, PhpResource link = null)
        {
            var resource = link ?? MySqlConnectionManager.GetInstance(ctx).GetLastConnection();

            return(resource as MySqlConnectionResource);
        }
Exemplo n.º 9
0
 /// <summary>
 /// Creates a connection resource using an existing <see cref="MySqlConnection"/> instance.
 /// </summary>
 /// <exception cref="ArgumentNullException">Provided instance is <c>null</c>.</exception>
 public static PhpResource mysql_connect(Context ctx, MySqlConnection dbconnection /*, bool leaveOpen*/)
 {
     return(new MySqlConnectionResource(MySqlConnectionManager.GetInstance(ctx), dbconnection ?? throw new ArgumentNullException(nameof(dbconnection))));
 }