class mysqlEasyHeper{ private string _conStr = "server=localhost; user id=root; port=3308; password=root; charset=utf8; pooling=true"; private MySqlConnection _con; public string conState{ get{ return _con == null ? "" : _con.State.ToString(); } } public MySqlConnection con{ get{ if(_con == null){ getConn(); } return this._con; } } public mysqlEasyHeper(){ try { _con = new MySqlConnection(_conStr); _con.Open(); } catch (Exception e) { throw e; } } private MySqlConnection getConn(){ try { _con = new MySqlConnection(_conStr); _con.Open(); } catch (Exception) { return null; } return _con; } private void excuteNoQuery(string queryStr, MySqlConnection connect){ if(String.IsNullOrEmpty(queryStr)) return; MySqlCommand query = new MySqlCommand(queryStr, connect); query.ExecuteNonQuery(); } public void createDatabase(string dataName){ if(string.IsNullOrEmpty(dataName))return; string sql = "create database if not exists " + dataName + ";"; excuteNoQuery(sql, _con); } public DataTable showDataBases(){ string sql = "show databases;"; DataTable dt = null; MySqlDataAdapter adapter = null; try { MySqlCommand query = new MySqlCommand(sql, _con); adapter = new MySqlDataAdapter(); dt = new DataTable(); adapter.SelectCommand = query; adapter.Fill(dt); } catch (Exception e) { return null; }finally{ adapter.Dispose(); } return dt; } public void dispose(){ if(_con != null){ if (_con.State == ConnectionState.Open) { _con.Close(); } _con.Dispose(); } } public void dbPoolTest(){ string _conStr = "server=localhost; user id=root; port=3308; password=root; charset=utf8; pooling=false"; MySqlConnection conn = new MySqlConnection(_conStr); conn.Open(); conn.Close(); } }