1
/****************************************************************************************
2
 * Copyright (c) 2009 Jeff Mitchell <mitchell@kde.org>                                  *
3
 *                                                                                      *
4
 * This program is free software; you can redistribute it and/or modify it under        *
5
 * the terms of the GNU General Public License as published by the Free Software        *
6
 * Foundation; either version 2 of the License, or (at your option) any later           *
7
 * version.                                                                             *
8
 *                                                                                      *
9
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
10
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
11
 * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
12
 *                                                                                      *
13
 * You should have received a copy of the GNU General Public License along with         *
14
 * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
15
 ****************************************************************************************/
16
17
#include "MySqlServerTester.h"
18
19
#include "core/support/Debug.h"
20
#include <mysql.h>
21
22
bool MySqlServerTester::testSettings( const QString &host, const QString &user, const QString &password, int port )
23
{
24
    DEBUG_BLOCK
25
    if( mysql_library_init( 0, NULL, NULL ) )
26
    {
27
        error() << "MySQL library initialization failed!";
28
        return false;
29
    }
30
31
    MYSQL* db = mysql_init( NULL );
32
33
    if( !db )
34
    {
35
        error() << "MySQL initialization failed";
36
        return false;
37
    }
38
39
    if( !mysql_real_connect( db, host.toUtf8(), user.toUtf8(), password.toUtf8(), NULL, port, NULL, CLIENT_COMPRESS ) )
40
    {
41
        mysql_close( db );
42
        db = 0;
43
        return false;
44
    }
45
    
46
    mysql_close( db );
47
    db = 0;
48
    return true;
49
}