LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   check data in mysql (https://www.linuxquestions.org/questions/programming-9/check-data-in-mysql-4175503753/)

derekchung_8080 05-02-2014 07:52 PM

check data in mysql
 
Hi, I just would like to write a perl script , this perl script do the following .

Check the parameter $data in a mysql database ( with user ID and password ) , if the $data is exist then return true , if not then return false , would advise how to write this script ? thanks

sundialsvcs 05-02-2014 11:16 PM

Ask your instructor . . .

NevemTeve 05-04-2014 06:03 AM

There is a client program by name mysql, exactly for uses like this. (Perl is not required, shell in enough.)
http://www.freebsd.org/cgi/man.cgi?q...lt&format=html

derekchung_8080 05-04-2014 06:33 AM

I have the below perl script to connect the mysql db , would advise how to make it to check if the parameter $data is exist or not , then return true or false ? thansk

use DBI
use strict;

my $driver = "mysql";
my $database = "TESTDB";
my $dsn = "DBI:$driver:database=$database";
my $userid = "testuser";
my $password = "test123";

my $dbh = DBI->connect($dsn, $userid, $password ) or die $DBI::errstr;

sundialsvcs 05-04-2014 07:15 AM

C'mon, you got that much from the CPAN page for DBI, or its easy equivalent. Ask your instructor to show you how to write a SELECT query and to see if it returns any results. Ask about COUNT(*).

Or, switch majors in college now. Switch to an art class and stop trying to ask the world to help you cheat on your homework. :tisk: Because, it only goes downhill from here. Computer programming does not consist of "learning enough about brake-pedals and steering wheels to successfully pilot a (say, Perl) motor-car around the block without crashing into a tree." No, it fundamentally consists of planning and then carrying-out a trip across the country, using whatever your car-of-choice (or of necessity ...) can do for you.

If you don't know what to do, and it appears right now that you do not, then it is fruitless for someone else to present to you a pretty packaged "answer" that actually does it ... because you will have learned nothing and will still know nothing of how to make a similar plan for yourself, to solve the next problem and the next and the next.

I'm not making fun of you: I'm telling you why you need to engage your instructor for help. Some of the time, I am an instructor.

I swear to you that I do not like to fill-in the little bubble on the opscan sheet that has an "F" in it, but I promise you also that I can always see it coming.

derekchung_8080 05-04-2014 10:29 AM

thanks reply ,

would advise how to chnage the above script ? thanks


All times are GMT -5. The time now is 03:23 PM.