[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Why am I getting a segmentation fault?



Try something like this:

MYSQL                   sqlHandle;
#define SQL_HOST        "localhost"
#define SQL_USER        "localuser"
#define SQL_PASS        "localpass"
#define SQL_DB          "localdb"

int connectSQL()
{
        MYSQL   *tmp;

        tmp = mysql_connect(&sqlHandle, SQL_HOST, SQL_USER, SQL_PASS);

        if (tmp == NULL)
		return 0; // failed to establish connection with the SQL server

	return (!mysql_select_db(&sqlHandle, SQL_DB));
}

Tom [debian@jojosarfo.org] wrote:
> 
> I'm wondering why I am getting a segmentation fault when selecting the db.
> I connect fine to the server. Any help would be great,
> 
> ==========================
> 
> #include <mysql.h>
> #include <iostream.h>
> 
> 
> MYSQL *mysql;
> MYSQL_RES *res;
> MYSQL_ROW row;
> 
> #define myDb "menagerie"
> 
> 
> int main()
> {
> 
> 
>   if (!mysql_connect(mysql,"host","username","password")){
>     cout << "Error connecting" << endl;
>     return 1;
>   }
> 
>   // this is where the fault is happening.
>   if (mysql_select_db(mysql, myDb)){
>     cout << "Error getting DB" << endl;
>     return 1;
>   }
> 
>   mysql_close(mysql);
> 
>   cout << "Wow it worked!" << endl;
>   return 0;
> 
> }
> =========================================
> 
> Tom
> 
> 
> -- 
> Unsubscribe?  mail -s unsubscribe debian-user-request@lists.debian.org < /dev/null
> 
> 

-- 
____________________________________________________________________________
Shao Zhang - Running Debian 2.1  ___ _               _____
Department of Communications    / __| |_  __ _ ___  |_  / |_  __ _ _ _  __ _ 
University of New South Wales   \__ \ ' \/ _` / _ \  / /| ' \/ _` | ' \/ _` |
Sydney, Australia               |___/_||_\__,_\___/ /___|_||_\__,_|_||_\__, |
Email: shao@cia.com.au                                                  |___/ 
_____________________________________________________________________________


Reply to: