List:General Discussion« Previous MessageNext Message »
From:Michael Widenius Date:June 9 1999 3:25pm
Subject:Help in executing a query
View as plain text  
>>>>> "Net-Lynx" == Net-Lynx  <santos@stripped> writes:

Net-Lynx> Hi All,
Net-Lynx> Being new to MySql, I wrote a simple program (see below) that connects to a
Net-Lynx> server, selects a database, performs a query ... you get the picture.
Net-Lynx> Anyway, I can connect and select a database, but then the program
Net-Lynx> fails when I try to execute a query with a "No Database selected".
Net-Lynx> Could someone tell me what I'm doing wrong? I don't understand why I'm
Net-Lynx> getting a "No Database Selected" right after the DB is selected...

Net-Lynx> I've place a comment where the code fails... Any help would be
Net-Lynx> appreciated...

Net-Lynx> Thanks,
Net-Lynx> Jorge


Net-Lynx> #include <stdio.h>
Net-Lynx> #include "/usr/local/include/mysql/mysql.h"

Net-Lynx> MYSQL sock;
Net-Lynx> MYSQL_RES *result;
Net-Lynx> MYSQL_ROW row;

Net-Lynx> int main(void) {
Net-Lynx> if (!mysql_real_connect(&sock,NULL,NULL,NULL,0,NULL,0)){
Net-Lynx> printf("Connect failed: %s\n",mysql_error(&sock));
Net-Lynx> return 0;
Net-Lynx> }
Net-Lynx> printf("Connected\n");

Net-Lynx> if (!mysql_select_db(&sock,"YESWIM")){
Net-Lynx> printf("DB Selection failed: %s\n",mysql_error(&sock));
Net-Lynx> return 0;
Net-Lynx> }
Net-Lynx> printf("DB selected\n");

Hi!

The problem is that mysql_select_db() return 0 if its ok and something 
else on error!

Remove the ! before mysql_select_db and try again!

(The problem is probably that "YESWIM" should be "yeswim")

Regards,
Monty
Thread
Help in executing a queryNet-Lynx9 Jun
  • Help in executing a queryMichael Widenius9 Jun
    • Re: Help in executing a queryNet-Lynx9 Jun