You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Thursday, November 18th 2004, 2:19am

Question about MySQL connection with QT

My code:
#include <my_global.h>
#include <mysql.h>
#include <qapplication.h>

static MySQL *conn
{
conn = mysql_init(NULL);
mysql_real_connect(conn,hostname,username,password,NULL,0,NULL,0);
exit(0);
}


when i make,there are some errors like this:
undeclaration reference to "mysql_init"
undeclaration reference to "mysql_real_connect"

what's the error about?
Help me,thank you!!!!!!!!!!

djanubis

Professional

  • "djanubis" is male

Posts: 1,370

Location: Moulins France

Occupation: Software ingeneering

  • Send private message

2

Thursday, November 18th 2004, 6:00am

RE: Question about MySQL connection with QT

Sounds the mysql.h include is not found in your incpath.
In linux, mysql-devel installs development headers in /usr/include/mysql
and you use it with
#include<mysql/mysql.h>

Before trying to make direct use of mysql API, did you try he abstract SQL drivers in qt ?
Never patch not working code. Rewrite it !
Never patch badly designed classes. Recreate them cleanly.
(Excerpts from Computing Bible)

Home of the Lab project

3

Thursday, November 18th 2004, 8:45am

RE: Question about MySQL connection with QT

thanks,djanubis
But what can i do about "SQL drivers in qt"?
thanks again!!!!!!!!!!

djanubis

Professional

  • "djanubis" is male

Posts: 1,370

Location: Moulins France

Occupation: Software ingeneering

  • Send private message

4

Thursday, November 18th 2004, 8:55am

RE: Question about MySQL connection with QT

Wich qt version and wich OS do you use.
Ie, most linux distros provide the qt-mysql, qt-odbc and qt-postgresql plugins already compiled. You only have to install packages and read SQL module from qt doc. This makes database connection very simple without dealing with specific database driver intricacies.
Never patch not working code. Rewrite it !
Never patch badly designed classes. Recreate them cleanly.
(Excerpts from Computing Bible)

Home of the Lab project

5

Friday, November 19th 2004, 2:19am

i use redhat 8.0and qt 3.0
Can you give me a completly code of mysql searcher in qt?
thank you very very much!!!!!!!!!!!!!!!!!!!!!!!!!!!

djanubis

Professional

  • "djanubis" is male

Posts: 1,370

Location: Moulins France

Occupation: Software ingeneering

  • Send private message

6

Friday, November 19th 2004, 6:44am

In your distro or using http://fr2.rpmfind.net try to find qt-mysql package for your distro with the right qt version. rpmfind is great for this. Install the package.

To know if the database driver is installed, use a very simple app:

Source code

1
2
3
4
5
6
7
8
#include <qapplication.h>
#include <qsqldatabase.h>

int main( int argc, char ** argv )
{
    QApplication a( argc, argv ) ;
    qDebug( QSqlDatabase::drivers().join( "\n" ) ) ;
}


or, even simpler, open designer and a project. In project menu, open database connections and check that QMYSQL3 driver is present.

After this, read SQL module documentation and, eventually, designer section dealing with some of database widgets QDataTable, QDataBrowser, QSqlForm and more.
Never patch not working code. Rewrite it !
Never patch badly designed classes. Recreate them cleanly.
(Excerpts from Computing Bible)

Home of the Lab project

7

Sunday, November 21st 2004, 9:46am

:)thanks
I will try it
:]

8

Monday, November 22nd 2004, 1:54am

Thank you!
I has connected the database.
Next i will write the code of data query.
If i has some questions, i hope you will help me again !
thank you.