Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Microsoft.VisualBasic;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Data;
- using System.Diagnostics;
- using MySql.Data.MySqlClient;
- public class Mysql
- {
- private const string mysql_sever = "HOST";
- private const string mysql_database = "DATABASE";
- private const int mysql_port = 3306;
- private const string mysql_username = "USERNMAE";
- private const string mysql_password = "PASSWORD";
- public MySqlConnection SqlConnection;
- public object connect()
- {
- dynamic mysql_serverstring = "Server=" + mysql_sever + ";User Id=" + mysql_username + ";Password=" + mysql_password + ";Database=" + mysql_database;
- SqlConnection = new MySqlConnection();
- SqlConnection.ConnectionString = mysql_serverstring;
- try {
- if (SqlConnection.State == ConnectionState.Closed) {
- SqlConnection.Open();
- Console.WriteLine(DateAndTime.Now + ": Successfully Connected to Database!");
- return true;
- } else {
- Console.WriteLine(DateAndTime.Now + ": Failed to Connected to Database!");
- SqlConnection.Close();
- return false;
- }
- } catch (Exception ex) {
- Console.WriteLine(DateAndTime.Now + ": Failed to connect to database! - " + ex.Message);
- return false;
- }
- }
- public object isconnected()
- {
- if (SqlConnection.State == ConnectionState.Closed == false) {
- return true;
- }
- return false;
- }
- public bool query(q)
- {
- try {
- if (isconnected()) {
- MySqlCommand cmd = new MySqlCommand(q, SqlConnection);
- return cmd.ExecuteNonQuery();
- } else {
- connect();
- return false;
- }
- } catch (Exception ex) {
- Console.WriteLine(DateAndTime.Now + ": My Sql Error - " + q + " - " + ex.Message);
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement