Jump to content

Archived

This topic is now archived and is closed to further replies.

anroy

MySQL C API problem

Recommended Posts

[i]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]

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.
[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" );
}
}[/code]


I also tried the following variation, with the same NULL results.
[code]#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" );
}

}[/code]

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

Share this post


Link to post
Share on other sites
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.  :-[

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.