MySQL C API problem
I hope this is the relevant forum for this question.
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> I also tried the following variation, with the same NULL results. Code:
#include </usr/local/mysql/include/mysql/mysql.h> 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 |
can you get any error info with mysql_error()
|
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. :o |
it could be said that another lesson would be to post the solution so that others can learn from your experience.
|
Quote:
The code snippet in my first post was not the actual story. I was unfortunately away from my source code when I posted so I just typed an approximation on the fly. Here is the actual code I was running at the time. Code:
int main() The condition if( mysql == NULL ) was simply a typo. I fixed it to be if( mysql != NULL ) So another lesson here is to literally copy-paste source code AS IS when posting on forums, rather relying on recollection or providing approximations. Having said that, even now I had to doctor a couple of areas in the code, such as username and password etc. |
congrats on getting it to work!
and good work on following up with the solution. you can be sure that someone will benefit from seeing a full example like this at some point in the future. -x |
and good work on following up with the solution. you can be sure that someone will benefit from seeing a full example like this at some point in the future.
And you were right!! Thanks! :D |
All times are GMT -5. The time now is 02:26 PM. |