In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
Editor to share with you how to use perl to access mysql database, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
one。 Install the DBI module
Step 1:
Download DBI.zip from the TOOLS column and unlock it into a temp directory with winzip after downloading. There are three files in total:
Readme
DBI.ppd
DBI.tar.gz
Step 2:
Under the DOS window, run the following DOS command in the temp directory:
Ppm install DBI.ppd
If you prompt an invalid command, you can run it in the perl/bin directory
two。 Install the DBD-Mysql module
Download DBD-Mysql.zip from the software download, the installation method is the same.
three。 Prepare the database
Start mysql, first create a database mydata, and then create a table address
Mysql > create database mydata
Query OK, 1 row affected (0.00 sec)
Mysql > use mydata
Database changed
Mysql > create table address (
-> id int (5) not null
-> name varchar (40) not null
-> email varchar (50) not null
-> telephone int (12) null)
Query OK, 0 rows affected (0.05 sec)
Enter some data:
Mysql > insert into address values (
-> 1 "Nighthawk", "Nighthawk", "163.netdog", "92384092")
Query OK, 1 row affected (0.00 sec)
four。 Below, use the perl program to insert several records and make queries.
Use DBI
# connecting to the database mydata
My $dbh = DBI- > connect ('DBI:mysql:mydata') or die "cannot connect to the database:". DBI- > errstr
Print "insert several records n"
My $sth = $dbh- > prepare (Q {
INSERT INTO address (id, name,email,telephone) VALUES (?)
})})
Print "enter record, enter end:"
While ($inputdata =) {
Chop $inputdata
Last unless ($inputdata)
My ($id, $name,$email, $tel) = split (/, /, $inputdata)
$sth- > execute ($id, $name, $email,$tel)
}
# $dbh- > commit
Print "print out the EMAIL address and phone number n according to the name entered below"
My $sth = $dbh- > prepare ('SELECT * FROM address WHERE name=?')
Or die $dbh- > errstr
Print "Please enter your name and press enter to finish:"
While ($inputname =) {
My @ data
Chomp $inputname
Last unless ($inputname)
Sth- > execute ($inputname) or die "error:". $sth- > errstr
While (@ data = $sth- > fetchrow_array ()) {
Print "Email:$data [2] t Telephone:$data [3] n"
}
}
# disconnect
$dbh- > disconnect
The above is all the contents of the article "how to access mysql database with perl". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.