@@ -17,6 +17,8 @@ These are the clients we actively test against to check are compatible with go-m
1717 - [ mariadb-java-client] ( #mariadb-java-client )
1818- Go
1919 - [ go-mysql-driver/mysql] ( #go-mysql-driver-mysql )
20+ - C
21+ - [ mysql-connector-c] ( #mysql-connector-c )
2022- Grafana
2123- Tableau Desktop
2224
@@ -30,12 +32,12 @@ import pymysql.cursors
3032connection = pymysql.connect(host = ' 127.0.0.1' ,
3133 user = ' root' ,
3234 password = ' ' ,
33- db = ' gitbase ' ,
35+ db = ' mydb ' ,
3436 cursorclass = pymysql.cursors.DictCursor)
3537
3638try :
3739 with connection.cursor() as cursor:
38- sql = " SELECT * FROM commit_files LIMIT 1"
40+ sql = " SELECT * FROM mytable LIMIT 1"
3941 cursor.execute(sql)
4042 rows = cursor.fetchall()
4143
@@ -53,11 +55,11 @@ connection = mysql.connector.connect(host='127.0.0.1',
5355 user = ' root' ,
5456 passwd = ' ' ,
5557 port = 3306 ,
56- database = ' gitbase ' )
58+ database = ' mydb ' )
5759
5860try :
5961 cursor = connection.cursor()
60- sql = " SELECT * FROM commit_files LIMIT 1"
62+ sql = " SELECT * FROM mytable LIMIT 1"
6163 cursor.execute(sql)
6264 rows = cursor.fetchall()
6365
@@ -72,9 +74,9 @@ finally:
7274import pandas as pd
7375import sqlalchemy
7476
75- engine = sqlalchemy.create_engine(' mysql+pymysql://root:@127.0.0.1:3306/gitbase ' )
77+ engine = sqlalchemy.create_engine(' mysql+pymysql://root:@127.0.0.1:3306/mydb ' )
7678with engine.connect() as conn:
77- repo_df = pd.read_sql_table(" commit_files " , con = conn)
79+ repo_df = pd.read_sql_table(" mytable " , con = conn)
7880 for table_name in repo_df.to_dict():
7981 print (table_name)
8082```
@@ -84,8 +86,8 @@ with engine.connect() as conn:
8486``` ruby
8587require " mysql"
8688
87- conn = Mysql ::new (" 127.0.0.1" , " root" , " " , " gitbase " )
88- resp = conn.query " SELECT * FROM commit_files LIMIT 1"
89+ conn = Mysql ::new (" 127.0.0.1" , " root" , " " , " mydb " )
90+ resp = conn.query " SELECT * FROM mytable LIMIT 1"
8991
9092# use resp
9193
@@ -96,10 +98,10 @@ conn.close()
9698
9799``` php
98100try {
99- $conn = new PDO("mysql:host=127.0.0.1:3306;dbname=gitbase ", "root", "");
101+ $conn = new PDO("mysql:host=127.0.0.1:3306;dbname=mydb ", "root", "");
100102 $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
101103
102- $stmt = $conn->query('SELECT * FROM commit_files LIMIT 1');
104+ $stmt = $conn->query('SELECT * FROM mytable LIMIT 1');
103105 $result = $stmt->fetchAll(PDO::FETCH_ASSOC);
104106
105107 // use result
@@ -118,11 +120,11 @@ const connection = mysql.createConnection({
118120 port: 3306 ,
119121 user: ' root' ,
120122 password: ' ' ,
121- database: ' gitbase '
123+ database: ' mydb '
122124});
123125connection .connect ();
124126
125- const query = ' SELECT * FROM commit_files LIMIT 1' ;
127+ const query = ' SELECT * FROM mytable LIMIT 1' ;
126128connection .query (query, function (error , results , _ ) {
127129 if (error) throw error;
128130
@@ -144,13 +146,13 @@ namespace something
144146 {
145147 public async Task DoQuery ()
146148 {
147- var connectionString = " server=127.0.0.1;user id=root;password=;port=3306;database=gitbase ;" ;
149+ var connectionString = " server=127.0.0.1;user id=root;password=;port=3306;database=mydb ;" ;
148150
149151 using (var conn = new MySqlConnection (connectionString ))
150152 {
151153 await conn .OpenAsync ();
152154
153- var sql = " SELECT * FROM commit_files LIMIT 1" ;
155+ var sql = " SELECT * FROM mytable LIMIT 1" ;
154156
155157 using (var cmd = new MySqlCommand (sql , conn ))
156158 using (var reader = await cmd .ExecuteReaderAsync ())
@@ -172,8 +174,8 @@ import java.sql.*;
172174
173175class Main {
174176 public static void main (String [] args ) {
175- String dbUrl = " jdbc:mariadb://127.0.0.1:3306/gitbase ?user=root&password=" ;
176- String query = " SELECT * FROM commit_files LIMIT 1" ;
177+ String dbUrl = " jdbc:mariadb://127.0.0.1:3306/mydb ?user=root&password=" ;
178+ String query = " SELECT * FROM mytable LIMIT 1" ;
177179
178180 try (Connection connection = DriverManager . getConnection(dbUrl)) {
179181 try (PreparedStatement stmt = connection. prepareStatement(query)) {
@@ -202,16 +204,71 @@ import (
202204)
203205
204206func main () {
205- db , err := sql.Open (" mysql" , " root:@tcp(127.0.0.1:3306)/gitbase " )
207+ db , err := sql.Open (" mysql" , " root:@tcp(127.0.0.1:3306)/mydb " )
206208 if err != nil {
207209 // handle error
208210 }
209211
210- rows , err := db.Query (" SELECT * FROM commit_files LIMIT 1" )
212+ rows , err := db.Query (" SELECT * FROM mytable LIMIT 1" )
211213 if err != nil {
212214 // handle error
213215 }
214216
215217 // use rows
216218}
217219```
220+
221+ ### #mysql-connector-c
222+
223+ ``` c
224+ #include < my_global.h>
225+ #include < mysql.h>
226+
227+ void finish_with_error (MYSQL * con)
228+ {
229+ fprintf(stderr, "%s\n", mysql_error(con));
230+ mysql_close(con);
231+ exit(1);
232+ }
233+
234+ int main(int argc, char ** argv)
235+ {
236+ MYSQL * con = NULL;
237+ MYSQL_RES * result = NULL;
238+ int num_fields = 0;
239+ MYSQL_ROW row;
240+
241+ printf("MySQL client version: %s\n", mysql_get_client_info());
242+
243+ con = mysql_init(NULL);
244+ if (con == NULL) {
245+ finish_with_error(con);
246+ }
247+
248+ if (mysql_real_connect(con, "127.0.0.1", "root", "", "mydb", 3306, NULL, 0) == NULL) {
249+ finish_with_error(con);
250+ }
251+
252+ if (mysql_query(con, "SELECT name, email, phone_numbers FROM mytable")) {
253+ finish_with_error(con);
254+ }
255+
256+ result = mysql_store_result(con);
257+ if (result == NULL) {
258+ finish_with_error(con);
259+ }
260+
261+ num_fields = mysql_num_fields(result);
262+ while ((row = mysql_fetch_row(result))) {
263+ for(int i = 0; i < num_fields; i++) {
264+ printf("%s ", row[i] ? row[i] : "NULL");
265+ }
266+ printf("\n");
267+ }
268+
269+ mysql_free_result(result);
270+ mysql_close(con);
271+
272+ return 0;
273+ }
274+ ```
0 commit comments