Jump to content


Photo

MySQL C API problem


  • Please log in to reply
1 reply to this topic

#1 anroy

anroy
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 09 August 2006 - 05:51 PM

I wanted to take this to MySQL Freaks but they are down I was directed back here.  However please be warned that this problem has nothing to do with PHP, only MySQL and C.  Moderaters, please shelve it if it is too irrelevant.

I set up MySQL 5.0.24 on an Ubuntu Linux machine, by downloading the source tarball.

For some reason I just can't seem to get mysql_init to work, it ALWAYS returns NULL!

On the MySQL site it says that this happens if there is insufficient memory.  I am sure that is not the case here.

Here is my code.
#include </usr/local/mysql/include/mysql/mysql.h>
#include <stdio.h>
#include <string.h>

int main()
{
	MYSQL mysql;
	rc = mysql_init( &mysql );
	if( rc == NULL ) {
		printf( "mysql_init returns NULL" );
	}
}


I also tried the following variation, with the same NULL results.
#include </usr/local/mysql/include/mysql/mysql.h>
#include <stdio.h>
#include <string.h>

int main()
{
	MYSQL *mysql;
	mysql = mysql_init( NULL );
	if( mysql == NULL ) {
		printf( "mysql_init returns NULL" );
	}

}

Does anybody have even the slightest clue as to why I would get NULL?

I compiled and linked using the following:
gcc sql_prog.c -o sql_prog -lz -lmysqlclient -L /usr/local/mysql/lib/mysql/

The compile and link were successful, as the message "mysql_init returns NULL" is properly output!

Also, the database server runs fine, the client programs mysqlshow, mysqladmin, etc. work fine.  They were also compiled on the same machine (I installed from source).

I am thinking about copying one of the client folders (like mysqlshow) in the MySQL source, modifying the code so it does what I need, and including it in the overall MySQL build as another Client.

However it is very time-consuming to configure and make the entire MySQL each time.  Maybe I can use this option?
shell> ./configure --without-server

Does this have any effect on the server that I am not aware of, like removing any files or settings?  I just want to rebuild the clients but want to leave the server as is.

Thanks,
Arka N. Roy


#2 anroy

anroy
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 11 August 2006 - 06:02 AM

Sorry it turns out this was a false alarm. Please forgive me for having wasted your time.

The lesson here is to check more carefully before posting to a forum.  :-[




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users