LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-06-2003, 09:25 AM   #1
rhuser
Member
 
Registered: Jan 2003
Posts: 55

Rep: Reputation: 15
i am tryin to write a script that will send data to MySQL


Hi

i am tryin to write a script that will send data to MySQL. I have images coming from a camera. i will be storing these images in a directory in my server (/home/me/images/ and each image will have a different name; the name will be the date of image. this is ok.), but i would like to send the information about the images to a database in MySQL. e.g. the name of the image, size of the image and date of image.

Any Ideas. Please any help would be aprreciated

mel
 
Old 03-06-2003, 10:20 AM   #2
Shak
Member
 
Registered: May 2002
Location: Huddersfield
Distribution: Redhat (7.2, 7.3, 8.0), Debian, Slackware, Gentoo, FreeBSD
Posts: 169

Rep: Reputation: 30
It would be pretty easy to do this in Perl, I suggest you have a look into the different modules and methods required:

http://www.cpan.org/ - A good place to look for modules

http://www.perl.com/ - Perl

Shak
 
Old 03-06-2003, 10:41 AM   #3
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
It's very easy in PHP.
 
Old 03-06-2003, 10:49 AM   #4
Shak
Member
 
Registered: May 2002
Location: Huddersfield
Distribution: Redhat (7.2, 7.3, 8.0), Debian, Slackware, Gentoo, FreeBSD
Posts: 169

Rep: Reputation: 30
PHP and Perl for this kind of thing are much of a muchness, I prefer Perl for system tasks and PHP for web based things

Shak
 
Old 03-06-2003, 11:59 AM   #5
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
I agree, PHP is best for web. Bourne shell then...
 
Old 03-06-2003, 12:04 PM   #6
Shak
Member
 
Registered: May 2002
Location: Huddersfield
Distribution: Redhat (7.2, 7.3, 8.0), Debian, Slackware, Gentoo, FreeBSD
Posts: 169

Rep: Reputation: 30
BASH is useful, but Perl is powerful. But always its the best tool for the job, you cant really say that any programming tool is better than any other except for how much you enjoy using them as they all do different things.

Shak
 
Old 03-06-2003, 12:22 PM   #7
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
What I'm really after is, I don't know Perl, so I find every way around using it. Perl is a very powerfull ( and cryptic ) and I have no doubt it could do the job.

Did we get off track?

Here is a small example of how to do something like this in C. The code below is missing pieces and will not compile as it, but you can use the syntax to build something that works for you.

Code:
#include <stdlib.h>
#include <string.h>
#include "parselog.h"
#include "logdb.h"

#include <mysql/mysql.h>

int init_db()
{
   MYSQL mysql;
   MYSQL_RES *result = NULL;
   MYSQL_ROW row;

   mysql_init(&mysql);

   if (!mysql_connect( &mysql, MYSQL_HOST, MYS
   {
      printf( "Failed to connect to DB, reason
              mysql_error( &mysql) );
      mysql_close( &mysql );
      return(0);
   }

   if (mysql_select_db( &mysql, MYSQL_DB ))
   {
      printf( "Failed to select table: Error:
      mysql_close(&mysql);
      return 0;
   }

}

int insert_entry( MYSQL *mysql, struct logEntr
{
   char query_str[500];
   MYSQL_RES *result = NULL;

   sprintf( query_str, "INSERT into entry "
                      "( month, day, time, hos
                      " mac, src, dst, len, to
                      " spt, dpt, urgp ) "
                      " values "
                      " %s, %d, %s, %s, %s, %s
                      " %d, %s, %s, %d, %d, %s
                      log -> szMonth,
                      log -> iDay,
                      log -> szTime,
                      log -> szHostname,
                      log -> szMessage,
                      log -> szIN,
                      log -> szOUT,
                      log -> szMAC,
                      log -> szDST,
                      log -> iLEN,
                      log -> szTOS,
                      log -> szPREC,
                      log -> iTTL,
                      log -> iID,
                      log -> szPROTO,
                      log -> iSPT,
                      log -> iDPT,
                      log -> iURGP );

   mysql_query( mysql, query_str );

   mysql_insert_id( mysql );
   result = mysql_use_result( mysql );

}

int close_db( MYSQL *mysql )
{
   mysql_close( mysql );
}
This would be main()
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "parselog.h"
#include "logdb.h"

#include <mysql/mysql.h>

main()
{
   MYSQL mysql;
   MYSQL_RES *result = NULL;
   MYSQL_ROW row;

   init_db( &mysql );
   parseFile( &mysql);
   close_db( &mysql );

}
Of course the missing code parselog.cpparseFile (much too large to fit here) has the line:
Code:
         insert_entry( mysql, &log );
 
Old 03-06-2003, 03:17 PM   #8
rhuser
Member
 
Registered: Jan 2003
Posts: 55

Original Poster
Rep: Reputation: 15
thanks for the help

it is all good, iknow php is good, i have written a script that access data in PHP, but ireally need a script to run in PERL. i have a project i am working on, and the missing piece is this.

PLease help
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
script for emailing mysql data MrJoshua Programming 5 06-14-2005 01:32 PM
write a shell script to send email yenonn Programming 4 02-11-2005 10:06 PM
Write a script to send an email from bash kpelczar Linux - Software 5 02-09-2005 04:19 PM
MySQL/PHP/Horde "Failed to write session data" Big Money Linux - Software 0 11-23-2004 01:33 PM
send automatic input to a script called by another script in bash programming jorgecab Programming 2 04-01-2004 12:20 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:40 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration