Click here to Skip to main content
15,895,777 members

QT MYSQL Database connectivity problems?

Gokulnath007 asked:

Open original thread
I have used the following code to connect to the mysql database, the connection succeeds, but nothing is happened in the database and also no table is created and the rows are not indeed updated. Kindly help me on this issue..

QSqlDatabase db= QSqlDatabase::addDatabase("QODBC");
     db.setDatabaseName("DRIVER={MYSQL ODBC 3.51 Driver};FIL={MYSQL};DBQ=screengrabber");
     db.setHostName("localhost");
     //db.setConnectOptions("CLIENT_ODBC");
     //db.setDatabaseName("screengrabber");
     db.setUserName("root");
     db.setPassword("1");
     ok = db.open();////Here ok is true...

     QSqlQuery query;
       query.exec("create table person (id int primary key, "
                  "firstname varchar(20), lastname varchar(20))");
       query.exec("insert into person values(101, 'Danny', 'Young')");



Default Re: MYSQL Qt connectivity?? I have used the following query which succees in inserting into the table. But how to bind the values instead of directly giving the values as below::
Qt Code:
bool qrylog=querylog.exec("INSERT INTO service_log (ip_address,date_time, service_status, logged_user) " "VALUES ('172.16.0.51','2011-07-28 15:55:09',1,'ramachandran')");
Here in database ip_address is varchar(20), date_time is datetime, service_status is integer and logged_user is varchar(30). Please help me fixing this issue::
Tags: QT, QT Creator

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900