How to connect to SQL through C? - mysql

I am making a project in C and I need database access. How would you connect to and access a database in the C language? I am using MySQL currently.

There are many solutions, depending on which database you are using and which OS you are using. One solution that will provide broad access to an array of combinations would be ODBC. You would connect to the database with a function like SQLConnect and use the other API functions to do your queries.
The links are windows specific, but you should be able to find analogs for whatever OS you will be using on your client side.

Depending on why you actually need to use a database (you didn't say) you could start using SQLite to develop your application.
Once you have it working and you have decided on which server you want to use (MySQL, MS SQL Server, Oracle, etc.) you can then read the documentation on creating a connection specific to that database server.

Related

How to connect to a remote MySQL from an Azure SQL server/database

sorry if title is not so clear, probably I am not finding what I need due I do not know how to search
I have few MySQL servers is separated online servers (from different wordpress) and I want to load some of the data on those databases/tablets into a SQL database located on Azure.
inside Azure portal itself I do not see where to establish external connections, neither at server level, neither at database level
I download and install Microsoft SQL Server Management Studio, connect to the server, I can see my databse and the master one, Security with logins, and Integration Service Catalog, nothing else.
I was looking for something like:
https://www.jetbrains.com/help/go/db-tutorial-connecting-to-ms-sql-server.html#step-3-connect-to-microsoft-sql-server-with-datagrip
but nowhere ...
maybe something like this:
https://www.devart.com/odbc/mysql/docs/microsoft_sql_server_manager_s.htm
but no Servers objects option available on my SSMS
Can be this done?
Note: Azure database is a basic wfor now, if that is a limitation
Some choices.
In your SQL Server Management Studio create a linked server pointing to each MySQL instance. You found the instructions for that. https://www.devart.com/odbc/mysql/docs/microsoft_sql_server_manager_s.htm But it probably will not work in Azure SQL Server; you don't have access to the underlying Windows OS to install stuff like MySQL ODBC drivers, which you need. (You could ask Azure techsupport if they can help.)
In each MySQL instance, try creating a federated table connection to appropriate table in SQL Server. That cross-vendor federation stuff only works in MariaDB, however; MySQL's federation only goes MySQL <--> MySQL.
Write yourself a purpose-built extract / transform / load (ETL) program, and arrange to run it every so often. Program it to connect to all the servers involved, retrieve the data needing to be transferred from your MySQL servers, and update / insert that data on the SQL server.
(edit) You may be able to use command-line SQL client programs. mysqldump, with its --compatible option, may generate usable INSERT statements in a file. You then may be able to use sqlcmd to run those INSERTs on your Azure server. It's going to take some hacking, and may take using sed(1) or awk(1) to make the MySQL output compatible with SQL Server.
I believe the third option is the most robust one for production use.

Database connection MySQL or Berkeley DB

Ive just recently learned SQL. There seems to be a few concepts I cant understand. Please check my statements. SQL is a language you are using to access data in MySQL? MySql is a software for a database server? So this means you can buy your own computer hardware and install MySql there and you can access your files in that specific hardware? Or is MySql only installed in hardwares owned by Oracle and you can only access files there by registering in Oracle?
Here is an example please correct the statement. Im trying to build a website for my students that take in a username and password. This website will use a scripting language that will connect to a database server. So I upload my xhtml, css files, and some scripting language to a webhost. Then those scripting files will connect me to my database server? This means I should have a database server. The database server are MySql, Appache Cassandra. To connect to those database server do I need my own harver server that has these database server installed or do I obtain membership from Oracle(?), Appache(?) to access there database server or is there other ways to store data? I think you guys can see my confusion.
You could say SQL is a standardized language to work with relational databases like MySQL, SQL Server Oracle, PostgreSQL etc They conform more or less to the standardized SQL language
MySQL is open source you can install it on just about any major OS / hardware architecture, for free you don't have to pay anyone anything except for support if you require that
It's possible to host your database on a server and allow remote apps to connect to it.
Apache Cassandra isn't exactly a relational database.
The first thing you need to do is learn to use Google to search for answers to your basic questions. I also recommend Wikipedia.org.
Those two websites can help you learn about what SQL is, MySQL is, scripting languages are, and what servers are.
I'll throw you a bone here. MySQL, PHP, and Apache (1 "p", not 2) are all free software. You can install them on "Windows" or "Linux".
If you're running Windows, also try using Google to research "WAMP stack" or "WAMP".

ODBC-ODBC bridge

I have a mysql db running on one linux server.
With an odbc connection for a web server on another linux box.
I would like to be able to use the/an odbc connection to the web server, to access mysql. This would be for an external app that is running on client machines.
I have done some googling, and there might be something called an ODBC-ODBC bridge.
I would like to just get a correct direction to go. So I don't head in the wrong direction.
If someone could point me at a specific bridge software. Or a tutorial. Or if this is even possible, and bridge is the correct thing to look for. etc...
thanks
Your post seems rather confused as to what ODBC is/does.
You have a webserver, you have a database. ODBC wil not join them together. You need something to implement your code with on the webserver - PHP, Perl, Ruby, Python, Java, C....
Bindings are available for most languages to talk to the ODBC client - which typically talks using the databases native protocol to the DBMS. However:
1) ODBC is somewhat constrained in its functionality - since it has to offer the lowest common denominator of functionality across a range of backends
2) all the languages I've listed (and more besides) support native (i.e. full function) connections to MySQL, and to other DBMS
Which rather begs the question, why do you want to to use ODBC?
There are instances where an ODBC-ODBC bridge solves a specific problem - where a DBMS provides an ODBC interface which is not supported on your client. This does not appear to be your problem.
Is your objective here to get the data from the database presented via the webserver or is to build something (anything) using ODBC?
If it's the former then forget about ODBC - it's irrelevant.
your webserver should have odbc connection to connect to MySQL database, and yes that you have. and when you do have that connectivity, I guess you won't really need your clients to connect to the MySQL database directly. because whatever query you want to run (an insert, or query operation), you just submit it to the webserver and it'll give fetch the query results for you.

What is the purpose of an ODBC driver when connecting to a MySQL server?

I've been wondering what are the benefits of using an ODBC driver to interface with a MySQL server? What advantage does that have over directly connecting to the server via TCP and firing off your SQL commands directly?
I'm working with a code base written in labVIEW that references a UDL file which references a data source and its associated ODBC driver to handle the connection to the server. I'm not yet convinced its necessary. I can see the benefit of using a driver if you are connecting to Microsoft Access or excel but if your recipient is an SQL server of some type why would you need a middle man to handle your SQL commands?
I have used the ODBC driver 3.51 for connecting to MySQL Community Server 5.1 for some time now. The ODBC driver allows you (on a Windows computer) to add your MySQL connection to the ODBC data sources list. Now you can reference this data source in many compatible applications. I have been able to use this ODBC connection in VB.Net applications as well as proprietary applications for printing and other functions with ODBC functionality.
I would say that when coding web or python applications i always use the built in MySQL packages, but if you need to access your data through VB.Net or another proprietary application (like a stand-alone windows app) you probably need to set up a system ODBC data source to access your database. To me the ODBC lets Windows access MySQL easily. Without Windows i don't think you need it.
Why ODBC and not JDBC? Some reasons come to mind in order of helpfulness when using JDBC:
Standard api to access the results from a query. To iterate over the results and to get the actual values with the appropriate type.
No need to know how the protocol works to connect to the server. Just use the host, user, password, send the SQL and iterate over the result.
Abstract out the connection to the database. Changing the database should be simpler.
Standard way to commit and rollback for transaction based changes.
In my experience, JDBC is very verbose. You need to write many lines to accomplish simple things. I've found the Spring JDBCTemplate wrapper to be an extremely easy to use alternative for simple stuff.

How do I connect webapp VB/LINQ to a MySQL database server on a Linux

I have a programmer who is using VB and LINQ; and I have a MySQL database that is running on a linux server. My programmer tells me that:
he cannot connect to the MySQL database via LINQ
if he was able to connect then it would require all sorts of rewriting
I don't know anything about LINQ but I thought it was an ORM. As such, any DB server that is supported should work just fine? Right?
OK, so maybe it's not an ORM... maybe it should generically connect to ODBC and render similar results?
Is there any advice out there for connecting VB+LINQ to MySQL?
you could use an open source project like http://code2code.net/DB_Linq/index.html
or you can use Linq to NHibernate: http://ayende.com/Blog/archive/2007/03/16/Linq-for-NHibernate.aspx
or even InterLinq if you want to make a multi-tier setup: http://www.codeplex.com/interlinq