element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
    About the element14 Community
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      •  Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Raspberry Pi
  • Products
  • More
Raspberry Pi
Raspberry Pi Forum RP & MYSQL database
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Raspberry Pi to participate - click to join for free!
Featured Articles
Announcing Pi
Technical Specifications
Raspberry Pi FAQs
Win a Pi
Raspberry Pi Wishlist
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 4 replies
  • Subscribers 705 subscribers
  • Views 521 views
  • Users 0 members are here
  • raspberry_pi
Related

RP & MYSQL database

e14 Contributor
e14 Contributor over 13 years ago

Not sure if I am in the right place. I have a manual toggle switch connected to the Raspberry GPIO. Is there anyway to have the switch status log to an SQL database. In other words, keeping track of the time/date when turned on or off?

  • Sign in to reply
  • Cancel
Parents
  • e14 Contributor
    e14 Contributor over 13 years ago

    It's certainly possible, the GPIO pins can be setup to interrupt on change. So you just need to write a bit of code that waits for the interrupt and when received logs that data into the db in whatever way you need.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • e14 Contributor
    e14 Contributor over 13 years ago in reply to e14 Contributor

    Thanks selsinork. Now that I know it can be done, all I need is someone to write me some code since I am only familiar with PHP :-( I wouldn't know where to start.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • e14 Contributor
    e14 Contributor over 13 years ago in reply to e14 Contributor

    No reason you couldn't do it in php, everything is a file after all image

     

    Maybe start here http://www.raspberrypi.org/phpBB3/viewtopic.php?f=44&t=7509 there's a demo program in C which just waits for an interrupt and then prints something to the screen as well as various references to other ways to access the feature from different languages.

     

    If you can catch the interrupts then writing to the database should be easy - I've not done enough in php to know how easy it would be though. Php being what it is, googling for 'php poll' just really isn't helpful image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • shabaz
    shabaz over 13 years ago in reply to e14 Contributor

    I'm not sure how to read interrupts from php either, but if the demo C program can do this, then one method would be:

    1. modify the C program so that it print out something in some defined format so that you know what interrupt occurred/switch got pressed

    2. in your php, use exec($prog, $outarr)

    3. compare $outarr[x] with what you expect (where x is the line number, I forget if it begins with 0 or 1)

    4. write to the database (assuming you know how to do this - requires php-mysql installed).

    Alternatively, you could do this entirely in one language (C) because there is a mysql API for C (again, not sure

    if that is avail for RP or not, but it is available for x86).

    Both of the above definitely work on x86 Linux (not tried RP for this).

    Also, there may be cleaner ways but I'm not sure.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Reply
  • shabaz
    shabaz over 13 years ago in reply to e14 Contributor

    I'm not sure how to read interrupts from php either, but if the demo C program can do this, then one method would be:

    1. modify the C program so that it print out something in some defined format so that you know what interrupt occurred/switch got pressed

    2. in your php, use exec($prog, $outarr)

    3. compare $outarr[x] with what you expect (where x is the line number, I forget if it begins with 0 or 1)

    4. write to the database (assuming you know how to do this - requires php-mysql installed).

    Alternatively, you could do this entirely in one language (C) because there is a mysql API for C (again, not sure

    if that is avail for RP or not, but it is available for x86).

    Both of the above definitely work on x86 Linux (not tried RP for this).

    Also, there may be cleaner ways but I'm not sure.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2026 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube