Det officielle C++ API hedder "Connector C++": http://forge.mysql.com/wiki/Connector_C%2B%2B
Det vil nok være det sikreste valg.
Hejsa. Jeg har installeret pakken og fulgt guiden, men jeg ved ikke hvordan jeg compiler med Connector C++. Den fortæller dog blot hvordan man bruger det og installere det, men ikke hvordan man compiler. Og jeg har heller ikke nogen "examples" mappe, som guiden hævder at jeg skulle have.
@Martin Slot; Det er ikke bare det specifikke program, men alle de ting jeg har prøvet. Jeg brugte udviklerens egen guides til hvordan man linkede osv, men det virkede ikke. Nu vil jeg så prøve Connector C++, det ser lovende ud.
Du skal bare lænke med biblioteket...sikkert Project properties eller så'n noget. Jeg bruger ikke selv dev-c++, men der plejer at være noget som hedder project properties.
Gjorde jeg skam også. Men det var ikke det eneste problem. Den manglede også mange header filer, som ikke var inkluderet i pakkerne, som jeg hentede.
Jeg prøvede at compile sådan her:
- Compiler: Default compiler
- Building Makefile: "C:\Dev-Cpp\Makefile.win"
- Executing make...
- make.exe -f "C:\Dev-Cpp\Makefile.win" all
- g++.exe -c main.cpp -o main.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include"
-
- In file included from C:/Dev-Cpp/include/cppconn/resultset.h:15,
- from main.cpp:6:
- C:/Dev-Cpp/include/cppconn/config.h:60: error: conflicting declaration 'typedef char int8_t'
- C:/Dev-Cpp/include/stdint.h:27: error: 'int8_t' has a previous declaration as `typedef signed char int8_t'
- C:/Dev-Cpp/include/cppconn/config.h:60: error: declaration of `typedef char int8_t'
- C:/Dev-Cpp/include/stdint.h:27: error: conflicts with previous declaration `typedef signed char int8_t'
- C:/Dev-Cpp/include/cppconn/config.h:60: error: declaration of `typedef char int8_t'
- C:/Dev-Cpp/include/stdint.h:27: error: conflicts with previous declaration `typedef signed char int8_t'
- C:/Dev-Cpp/include/cppconn/config.h:75: error: conflicting declaration 'typedef long int int32_t'
- C:/Dev-Cpp/include/stdint.h:31: error: 'int32_t' has a previous declaration as `typedef int int32_t'
- C:/Dev-Cpp/include/cppconn/config.h:75: error: declaration of `typedef long int int32_t'
- C:/Dev-Cpp/include/stdint.h:31: error: conflicts with previous declaration `typedef int int32_t'
-
- C:/Dev-Cpp/include/cppconn/config.h:75: error: declaration of `typedef long int int32_t'
- C:/Dev-Cpp/include/stdint.h:31: error: conflicts with previous declaration `typedef int int32_t'
- C:/Dev-Cpp/include/cppconn/config.h:79: error: conflicting declaration 'typedef long unsigned int uint32_t'
- C:/Dev-Cpp/include/stdint.h:32: error: 'uint32_t' has a previous declaration as `typedef unsigned int uint32_t'
- C:/Dev-Cpp/include/cppconn/config.h:79: error: declaration of `typedef long unsigned int uint32_t'
- C:/Dev-Cpp/include/stdint.h:32: error: conflicts with previous declaration `typedef unsigned int uint32_t'
- C:/Dev-Cpp/include/cppconn/config.h:79: error: declaration of `typedef long unsigned int uint32_t'
- C:/Dev-Cpp/include/stdint.h:32: error: conflicts with previous declaration `typedef unsigned int uint32_t'
-
- In file included from C:/Dev-Cpp/include/cppconn/statement.h:15,
- from main.cpp:7:
- C:/Dev-Cpp/include/cppconn/config.h:60: error: conflicting declaration 'typedef char int8_t'
- C:/Dev-Cpp/include/stdint.h:27: error: 'int8_t' has a previous declaration as `typedef signed char int8_t'
- C:/Dev-Cpp/include/cppconn/config.h:60: error: declaration of `typedef char int8_t'
- C:/Dev-Cpp/include/stdint.h:27: error: conflicts with previous declaration `typedef signed char int8_t'
- C:/Dev-Cpp/include/cppconn/config.h:60: error: declaration of `typedef char int8_t'
- C:/Dev-Cpp/include/stdint.h:27: error: conflicts with previous declaration `typedef signed char int8_t'
- C:/Dev-Cpp/include/cppconn/config.h:75: error: conflicting declaration 'typedef long int int32_t'
- C:/Dev-Cpp/include/stdint.h:31: error: 'int32_t' has a previous declaration as `typedef int int32_t'
- C:/Dev-Cpp/include/cppconn/config.h:75: error: declaration of `typedef long int int32_t'
- C:/Dev-Cpp/include/stdint.h:31: error: conflicts with previous declaration `typedef int int32_t'
-
- C:/Dev-Cpp/include/cppconn/config.h:75: error: declaration of `typedef long int int32_t'
- C:/Dev-Cpp/include/stdint.h:31: error: conflicts with previous declaration `typedef int int32_t'
- C:/Dev-Cpp/include/cppconn/config.h:79: error: conflicting declaration 'typedef long unsigned int uint32_t'
- C:/Dev-Cpp/include/stdint.h:32: error: 'uint32_t' has a previous declaration as `typedef unsigned int uint32_t'
- C:/Dev-Cpp/include/cppconn/config.h:79: error: declaration of `typedef long unsigned int uint32_t'
- C:/Dev-Cpp/include/stdint.h:32: error: conflicts with previous declaration `typedef unsigned int uint32_t'
- C:/Dev-Cpp/include/cppconn/config.h:79: error: declaration of `typedef long unsigned int uint32_t'
- C:/Dev-Cpp/include/stdint.h:32: error: conflicts with previous declaration `typedef unsigned int uint32_t'
-
- make.exe: *** [main.o] Error 1
-
- Execution terminated
Dette er min kode(et example jeg har fundet).
- #include <stdlib.h>
- #include <iostream>
-
- #include <cppconn/driver.h>
- #include <cppconn/exception.h>
- #include <cppconn/resultset.h>
- #include <cppconn/statement.h>
- #include <cppconn/prepared_statement.h>
-
- int main(){
-
- sql::Driver *driver;
- sql::Connection *con;
- sql::Statement *stmt;
- sql::ResultSet *res;
- sql::PreparedStatement *pstmt;
-
- try{
- driver = get_driver_instance();
- con = driver->connect("tcp://127.0.0.1:3306", "root", "root");
- con->setSchema("test");
-
- stmt = con->createStatement();
- stmt->execute("insert into example values(4,'four'),(5, 'five')");
- delete stmt;
-
- pstmt = con->prepareStatement("select * from example");
- res = pstmt->executeQuery();
- while (res->next())
- std::cout<<res->getInt("id")<<" "<<res->getString("data")<<std::endl;
- delete res;
- delete pstmt;
-
- pstmt = con->prepareStatement("delete from example where id=?");
- pstmt->setInt(1,4);
- pstmt->executeUpdate();
- pstmt->setInt(1,5);
- pstmt->executeUpdate();
-
- delete pstmt;
-
- delete con;
- }catch(sql::SQLException &e){
- std::cout<<e.what();
- }
- }
Jeg er heller ikke sikker på at om jeg skal linke noget. Så det har jeg ikke gjort
Indlæg senest redigeret d. 16.10.2010 12:25 af Bruger #15047