{"id":23301593,"url":"https://github.com/jdforsythe/mysqlconnection","last_synced_at":"2025-08-22T07:31:39.987Z","repository":{"id":137591495,"uuid":"56203906","full_name":"jdforsythe/MySQLConnection","owner":"jdforsythe","description":"Simple library to make it much easier to use MySQL in Visual Studio projects","archived":false,"fork":false,"pushed_at":"2016-04-14T03:21:52.000Z","size":10,"stargazers_count":8,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-12T22:43:04.242Z","etag":null,"topics":["database","dotnet","dotnet-framework","mysql","visual-studio"],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jdforsythe.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-04-14T03:19:02.000Z","updated_at":"2021-08-11T07:38:48.000Z","dependencies_parsed_at":"2023-03-23T01:45:59.461Z","dependency_job_id":null,"html_url":"https://github.com/jdforsythe/MySQLConnection","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/jdforsythe/MySQLConnection","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jdforsythe%2FMySQLConnection","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jdforsythe%2FMySQLConnection/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jdforsythe%2FMySQLConnection/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jdforsythe%2FMySQLConnection/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jdforsythe","download_url":"https://codeload.github.com/jdforsythe/MySQLConnection/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jdforsythe%2FMySQLConnection/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271604728,"owners_count":24788761,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-22T02:00:08.480Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database","dotnet","dotnet-framework","mysql","visual-studio"],"created_at":"2024-12-20T10:14:37.611Z","updated_at":"2025-08-22T07:31:34.972Z","avatar_url":"https://github.com/jdforsythe.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"﻿# MySQLConnection\n\nMySQLConnection makes it easier to use MySQL in your Visual Studio applications by\nabstracting the implementation of the MySQL .NET Connector away so you can work with\nstrictly native .NET data types.\n\nThis class implements the `IDisposable` interface, and should be used _exclusively_\nwith the `using()` pattern to ensure proper cleanup of connections.\n\n## Quick Example\n\n```c#\nstring myValue;\n\nusing (MySQLConn sql = new MySQLConn(connectionString)) {\n  sql.Query = \"SELECT my_column FROM table LIMIT 1\";\n  myValue = sql.selectQueryForSingleValue();\n}\n\nConsole.WriteLine(myValue);\n```\n\n## Create a connection\n\nAgain, always use `using()`. The `connectionString` parameter passed to the `MySQLConn`\nconstructor is the same format as you would use for the MySQL .NET Connector library:\n\n[https://dev.mysql.com/doc/connector-net/en/connector-net-programming-connecting-open.html]\n\n```c#\nstring connectionString = \"server=127.0.0.1; uid=root; pwd=12345; database=test;\";\n// or\nstring connectionString = \"Data Source=127.0.0.1; user id=root; password=12345; database=test;\";\n// and add any options at the end, such as AllowZeroDateTime=false\n\nusing (MySQLConn sql = new MySQLConn(connectionString)) {}\n```\n\nOr you can pass the parameters individually\n\n```\n// (server, database, username, password, options_string)\nusing (MySQLConn sql = new MySQLConn(\"127.0.0.1\", \"test\", \"root\", \"12345\", \"AllowZeroDateTime=false\")) {}\n```\n\n## Setting a query\n\nQueries are set on the `.Query` property.\n\n```c#\nsql.Query = \"SELECT * FROM table\";\n```\n\n### Parameterized queries\n\nParameters are set in the query the same way as the standard MySQL .NET Connector.\n\n```c#\nsql.Query = \"SELECT * FROM table WHERE id=@IdNumber\";\n```\n\n#### Add parameter value\n\n```c#\nsql.addParam(\"@IdNumber\", \"1\");\n```\n\n#### Remove previously-set parameter value\n```c#\nsql.removeParam(\"@IdNumber\");\n```\n\n#### Update previously-set parameter with new value\n```c#\nsql.updateParam(\"@IdNumber\", \"2\");\n```\n\n#### Clear all previously-set parameters\n```c#\nsql.clearParams();\n```\n\n## Available SQL methods\n\n### selectQueryForSingleValue()\n\n* returns a `string`, or `NULL`, if there is no result from the database\n* used when querying for a single column in a single record\n\n```c#\nstring myValue;\nusing (MySQLConn sql = new MySQLConn(connectionString)) {\n  sql.Query = \"SELECT my_column FROM table LIMIT 1\";\n  myValue = sql.selectQueryForSingleValue();\n}\n```\n\n### selectQueryForSingleRecord()\n\n* returns a `Dictionary\u003cstring, string\u003e`, or `NULL` if there is no result from the database\n* used when querying for a single record but any number of columns\n* dictionary is of form `\u003ccolumn_name, value\u003e`\n\n```c#\nDictionary\u003cstring, string\u003e myRecord;\nusing (MySQLConn sql = new MySQLConn(connectionString)) {\n  sql.Query = \"SELECT * FROM my_column WHERE id=@IdNumber LIMIT 1\";\n  sql.addParam(\"@IdNumber\", \"42\");\n  myRecord = sql.selectQueryForSingleRecord();\n}\n```\n\n### selectQueryForSingleColumn()\n\n* returns a `List\u003cstring\u003e`\n* returns an empty `List\u003cstring\u003e` if there is no result from the database (this allows a\n  `foreach` on the result without a `NullReferenceException`)\n* used when querying for a single column, but any number of records\n\n```c#\nList\u003cstring\u003e myColVals;\nusing (MySQLConn sql = new MySQLConn(connectionString)) {\n  sql.Query = \"SELECT my_column FROM table\";\n  myColVals = sql.selectQueryForSingleColumn();\n}\n```\n\n### selectQuery()\n\n* returns a `List\u003cDictionary\u003cstring, string\u003e\u003e` representing a list of the records\n* returns an empty `List\u003cDictionary\u003cstring, string\u003e\u003e` if there is no result from the\n  database (this allows a `foreach` on the result without a `NullReferenceException`)\n* used when querying for multiple columns and rows\n\n```c#\nList\u003cDictionary\u003cstring, string\u003e\u003e tableRows;\nusing (MySQLConn sql = new MySQLConn(connectionString)) {\n  sql.Query = \"SELECT * FROM table\";\n  tableRows = sql.selectQuery();\n}\n```\n\n### insertQuery()\n\n* returns an `int` indicating the number of affected rows\n\n```c#\nint affectedRows = 0;\nusing (MySQLConn sql = new MySQLConn(connectionString)) {\n  sql.Query = \"INSERT INTO table (my_column_1, my_column_2) VALUES (@Col1, @Col2)\";\n  sql.addParam(\"@Col1\", \"value_one\");\n  sql.addParam(\"@Col2\", \"value_two\");\n  affectedRows = sql.insertQuery();\n}\n```\n\n### updateQuery()\n\n* returns an `int` indicating the number of affected rows\n\n```c#\nint affectedRows = 0;\nusing (MySQLConn sql = new MySQLConn(connectionString)) {\n  sql.Query = \"UPDATE table SET my_column_1=@Col1, my_column_2=@Col2 WHERE id=@IdNumber LIMIT 1\";\n  sql.addParam(\"@Col1\", \"value_one\");\n  sql.addParam(\"@Col2\", \"value_two\");\n  sql.addParam(\"@IdNumber\", \"42\");\n  affectedRows = sql.updateQuery();\n}\n```\n\n### deleteQuery()\n\n* returns an `int` indicating the number of affected rows\n\n```c#\nint affectedRows = 0;\nusing (MySQLConn sql = new MySQLConn(connectionString)) {\n  sql.Query = \"DELETE FROM table WHERE id=@IdNumber\";\n  sql.addParam(\"@IdNumber\", \"42\");\n  affectedRows = sql.deleteQuery();\n}\n```\n\n### loadDataInfile()\n\n* returns an `int` indicating the number of affected rows\n* uses `LOAD DATA INFILE` to load bulk records into the database\n\n```c#\nint affectedRows = 0;\nstring tableName = \"table\",\n       fieldTerminator = \",\",\n       lineTerminator = \"\\r\\n\",\n       filename = \"infile.csv\",\n       linesToSkip = \"1\";\n\nusing (MySQLConn sql = new MySQLConn(connectionString)) {\n  affectedRows = sql.loadDataInfile(tableName, fieldTerminator, lineTerminator, filename, linesToSkip);\n}\n```\n\n## Exceptions\n\n* Throws `ObjectDisposedException` if the class has been disposed - this probably shouldn't happen\n* Throws generic `Exception` if no connection was opened (not connection error) - also probably shouldn't happen\n* Throws generic `Exception` if the `Query` property is empty\n* Throws generic `Exception` if the any of the connection paramters are null or empty strings\n* Throws standard MySQL Connector exceptions for any database connection or query errors\n\n## Contributions\n\nIssues and pull requests are always welcome\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjdforsythe%2Fmysqlconnection","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjdforsythe%2Fmysqlconnection","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjdforsythe%2Fmysqlconnection/lists"}