#1  
Old 4th October 2009, 11:40
dinesh.4126 dinesh.4126 is offline
Junior Member
 
Join Date: Jul 2009
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
 
Default MYSQL Using C API

Hi,
I am not big champ. of C.Next thing I am trying to do using these value 0xFE and 0x02 to control the I/O of board using MYSQL C based API at baord side.And using PHP admin to insert the value in MYSQL Database.And hotter_alert | varchar(40) | YES | | NULL | | hotter_alert is the field name and want to control the I/O of board from server side by inserting value.From BOARD side I am able tho fetch hooter_alert field value as row[0] and *PCDR is pointer to which want to assign row[0] value.Problem I am getting is that I am able to fetch the value from Database but Not able to assign properly this value *PCDR register.What I thought Problem is that row[0] value fetching from DATABASE come in string of character as such it's printing right value only when %s is given.And *PCDR is declared as unsigned int.Please suggest me How can I assign row[0] value to *PCDR register,so that I can control I/O from server side.
Code:
#include <stdio.h>
#include <stdlib.h>
#include "mysql.h"
#include<unistd.h>
#include<sys/types.h>
#include<sys/mman.h>
#include<stdio.h>
#include<fcntl.h>
#include<string.h>

void exiterr(int exitcode)
{
    fprintf( stderr, "%s\n", mysql_error(conn) );
    exit( exitcode );
}
int main(int argc, char **argv)
{
   MYSQL *conn;
   MYSQL_RES *res;
   MYSQL_ROW row;
    uint i = 0;
  char *server = "10.64.21.63";
   char *user = "root";
   char *password = "PASSWORD"; /* set me first */
   char *database = "mysql";
 unsigned char *start;
   volatile unsigned int *PCDR, *PCDDR;
   int fd = open("/dev/mem", O_RDWR);
start = mmap(0, getpagesize(), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0x80840000);
   PCDR = (unsigned int *)(start + 0x08);     // port c data register
   PCDDR = (unsigned int *)(start + 0x18);    // port c direction register

   (!mysql_real_connect(conn, server,
         user, password, database, 0, NULL, 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(&mysql)))
        exiterr(4);

    while((row = mysql_fetch_row(res))) {
        for (i=0 ; i < mysql_num_fields(res); i++) 
char * val=row[0]
*PCDDR = 0x01; // Make bit 0 an output Port C bit 0 is connected to the FET
*PCDR = val; // Turn the FET on
 printf("%s\n",row[0]);
    }

if (!mysql_eof(res))
        exiterr(5);

    mysql_free_result(res);
    mysql_close(&mysql);
   close(fd);
   return 0;
}
Reply With Quote
Sponsored Links
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How To Set Up A Load-Balanced MySQL Cluster => can't connect API node sanocli HOWTO-Related Questions 1 19th June 2008 16:12
Problem installing MySQL on suse 10.3 Txchaser Installation/Configuration 20 18th April 2008 01:05
Management/system config/settings & /server/settings not working!! dactor Installation/Configuration 9 6th February 2008 09:11
Messed up ISPConfig-2.2.8 Upgrade Morons Installation/Configuration 4 29th November 2006 12:17
Mandriva 10.2 Perfect Setup Install Problems... ctroyp Installation/Configuration 12 30th December 2005 16:04


All times are GMT +2. The time now is 07:54.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.