Jump to content

MySQL C API problem


anroy

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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.