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));
}试试看加上mysql_options()
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));
}试试看加上mysql_options()
char *dbhost_billing="127.0.0.1";
char *dbuser_billing="root";
char *dbpassword_billing="";
int dbport_billing=3306;
if ((ldap_billingd= mysql_init(NULL))==NULL)
{ printf("ldap_billingd: %s",mysql_error(ldap_billingd));
}
log("mysql_init is finished! \n");
if (mysql_real_connect(ldap_billingd,dbhost_billing,dbuser_billing,dbpassword_billing,"test",dbport_billing,NULL,0) <0)
{
printf("-----------------ldap_billingd: %s----------------",mysql_error(ldap_billingd));
}
printf("mysql_real_connect is finished! \n");
,"test",是数据库名
例如:
mysql_real_connect(&mysql,"localhost","root","dddd","test", 3306, NULL, 0)