DebianThis forum is for the discussion of Debian Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Below is MYSQL using C code and hotter_alert is field and I want to fetch particular row [4]=2 value of hotter_alert.If I am printing row[0] its printing all the row value of field hotter_alert.
mysql> select hotter_alert from location;
+--------------+
| hotter_alert |
+--------------+
| 0 |
| 0 |
| 0 |
| 0 |
| 2 |
+--------------+
5 rows in set (0.00 sec)
Code:
#include <stdio.h>
#include <stdlib.h>
#include "mysql.h"
MYSQL *conn;
MYSQL_RES *res;
MYSQL_ROW row;
void exiterr(int exitcode)
{
fprintf( stderr, "%s\n", mysql_error(conn) );
exit( exitcode );
}
int main()
{
uint i = 0;
char * server = "10.64.21.63";
char *user = "root";
char * password = "passwd";
//char *password = "rrr777"; /*set me first */
char *database = "location";
conn = mysql_init(NULL);
/* Connect to database */
if (!mysql_real_connect(conn, server,
user, password, database, 0, 0, 0))
exiterr(1);
if (mysql_select_db(conn,"location"))
exiterr(2);
if (mysql_query(conn,"SELECT hotter_alert from location"))
exiterr(3);
if (!(res = mysql_store_result(conn)))
exiterr(4);
while((row = mysql_fetch_row(res))) {
// for (i=0 ; i < mysql_num_fields(res); i++)
{
printf("%s \n", row[0]);
}
}
if (!mysql_eof(res))
exiterr(5);
mysql_free_result(res);
mysql_close(conn);
}
output of above program even though I am printing row[0].Quite strange
root@yatin-desktop:/home/yatin/Desktop# ./final
0
0
0
0
2
Below is the MYSQL C api code and used while infinite loop to fetch the data from database continuously.But .exe file runs only for few minute after printing the value on terminal its print killed.Can somebody help me if am using while infinite loop since its failed to print infinite row value.
-------------------------
--
--
--
1
1
1
1
1
1
Killed
--------------------------
Code:
#include <stdio.h>
#include <stdlib.h>
#include "mysql.h"
MYSQL *conn;
MYSQL_RES *res;
MYSQL_ROW row;
void exiterr(int exitcode)
{
fprintf( stderr, "%s\n", mysql_error(conn) );
exit( exitcode );
}
int main()
{
uint i = 0;
char * server = "10.64.21.63";
char *user = "root";
char * password = "passwd";
//char *password = "rrr777"; /*set me first */
char *database = "location";
conn = mysql_init(NULL);
/* Connect to database */
if (!mysql_real_connect(conn, server,
user, password, database, 0, 0, 0))
exiterr(1);
if (mysql_select_db(conn,"location"))
exiterr(2);
while (1)
{
if (mysql_query(conn,"SELECT hotter_alert from location"))
exiterr(3);
if (!(res = mysql_store_result(conn)))
exiterr(4);
while((row = mysql_fetch_row(res))) {
// for (i=0 ; i < mysql_num_fields(res); i++)
{
printf("%s \n", row[0]);
}
}
}
if (!mysql_eof(res))
exiterr(5);
mysql_free_result(res);
mysql_close(conn);
}
1. while (1)
2. {
3. /* send SQL query */
4. if (mysql_query(conn, "select *from location where id=5")) {
5. fprintf(stderr, "%s\n", mysql_error(conn));
6. exit(1);
7. }
8.
9. res = mysql_use_result(conn);
10.
11. /* output table name */
12. while ((row = mysql_fetch_row(res)) != NULL)
13. printf("%s \n", row[18]);
and when while loop is used again it ends with out of memory error.Please suggest me why such error is coming.
-------
5
5
5
5
5
5
5
5
5
5
5
5
Out of memory (Needed 8164 bytes)
Hi,
I compiled the code MYSQL C API along with C code and run ./a.out file.And I want this ./a.out to keep running continuous so that when I enter new value of particular field at myadmin php its value should be updated at MYSQL Client.So,is their any way I run ./a.out file continuous.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.