Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
mysql\u errno始终返回0_Mysql_C - Fatal编程技术网

mysql\u errno始终返回0

mysql\u errno始终返回0,mysql,c,Mysql,C,我尝试使用错误的用户或密码连接到服务器,但正如预期的那样,连接失败,但mysql\u errno始终返回0。我的mysql安装有问题吗 编辑:我正在使用c程序连接 int main(int argc, char *argv[]) { MYSQL my_connection; mysql_init(&my_connection); if (mysql_real_connect( &my_connection,

我尝试使用错误的用户或密码连接到服务器,但正如预期的那样,连接失败,但mysql\u errno始终返回0。我的mysql安装有问题吗

编辑:我正在使用c程序连接

int main(int argc, char *argv[]) {
    MYSQL my_connection;
    mysql_init(&my_connection);
    if (mysql_real_connect(
            &my_connection,
            "localhost",
            "rick",
            "I do not know",
            "foo", 0, NULL, 0)) {
        printf("Connection success\n");
        mysql_close(&my_connection);
    } else {
        fprintf(stderr, "Connection failed\n");
        if (mysql_errno(&my_connection)) {
            fprintf(stderr, "Connection error %d: %s\n",
                    mysql_errno(&my_connection), mysql_error(&my_connection));
        }
    }
    return EXIT_SUCCESS;
}
书中的输出应该是错误1045:
在我的例子中,它是0,只打印连接失败。

mysql\u errno()
只报告来自有效连接的错误

错误号来自实际数据库。它如何在没有连接的情况下检索这些数据

您会注意到,在中,他们不关心失败连接的错误号

MYSQL mysql;

mysql_init(&mysql);
mysql_options(&mysql,MYSQL_READ_DEFAULT_GROUP,"your_prog_name");
if (!mysql_real_connect(&mysql,"host","user","passwd","database",0,NULL,0))
{
    fprintf(stderr, "Failed to connect to database: Error: %s\n",
          mysql_error(&mysql));
}

我试图实现一本linux书中的一个示例。@dasman也许你应该用书中的示例和/或代码更新你的问题