MySQL C API problem
Posted: Wed Aug 09, 2006 1:24 pm
feyd | Please use
I also tried the following variation, with the same NULL results.
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
feyd | Please use[/syntax]
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
This problem has to do with using MySQL in a C program.
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.
[syntax="c"]#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.
Code: Select all
#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" );
}
}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
feyd | Please use[/syntax]
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]