4

I have this very short program. For some reason mysql_init always returns null for me. According to the documentation, this happens if there isn't enough memory. How can this be? It's just these few lines of code.

#include "mysql.h"

int main()
{
    MYSQL * mysql;
    mysql = mysql_init(0);
    // here mysql is 0
    return 0;
}

I use Visual Studio 2015 and the lib from mariadb-10.1.8-win32.zip .

edit: I made it work a bit. I was compiling with debug Settings in visual Studio and linked to libmysqld.lib. I also copies libmysqld.dll in the work dir. That resulted in the ffect I describe above. I tried to link to libmysql.lib and copies libmysql.dll to the work dir and that worked. I don't plan to debug mysql code, so I can live with that. It's still strange though why the debug lib doesn't work for the same code.

marc40000
  • 3,167
  • 9
  • 41
  • 63
  • Don't use the deprecated `mysql_*` interface; use the `mysqli_*` interface. – Rick James Nov 03 '15 at 03:14
  • mysqli is just php. There is only one native mysql c connector lib which has mysql_* functions. In php, mysql as well as mysqli both use that one native c lib internally. – marc40000 Nov 07 '15 at 00:28
  • 1
    In multi-threaded environments you are supposed to call [`mysql_library_init`](https://dev.mysql.com/doc/refman/5.6/en/mysql-library-init.html) first. Also see [mysql_init(NULL) segmentation fault](https://stackoverflow.com/q/12851488/608639) – jww Feb 17 '19 at 23:23

1 Answers1

3

if you link with libmysqld.lib, mysql_init will return NULL or crash. I test on mysql5.6 5.7 win10 vs2017.

the correct is libmysql.lib.

liuaifu
  • 147
  • 1
  • 8