473,385 Members | 2,269 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

how to insert a query into MYsql Db residing on my local host

11
Hi Guys, I am a beginner to perl.
I need a perl package which will perform basic DB operations like select , insert,update,delete operation MySql DB.

i Have a Mysql DB which resides on my local machine.DB Deatils are :
Localhost,MySql,DatabaseName:perltest, username:root,pwd:sierra,table:samples with coulms :id,name,phone

I am done with selecting the rows in DB. I need Sample code for inserting , updating and deleting . Please provide some basic infor regarding these.

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl -w 
  2.  
  3. use DBI; 
  4.  
  5. $dbh = DBI->connect('dbi:mysql:perltest','root','sierra') 
  6.  
  7. or die "Connection Error: $DBI::errstr\n"; 
  8.  
  9. $sql = "select * from samples"; 
  10.  
  11. $sth = $dbh->prepare($sql); 
  12.  
  13. $sth->execute 
  14.  
  15. or die "SQL Error: $DBI::errstr\n"; 
  16.  
  17. while (@row = $sth->fetchrow_array) { 
  18.  
  19. print "@row\n"; 
  20.  
  21. }
  22.  
Similarly i Need code for Inserting and updating and deleting operations and all these functions as a package. Can guyz help me in how to proceed for these things.

You can mail me ur proceeding to this id EMAILS REMOVED

Thanks in Advance
Koti.
Oct 29 '08 #1
3 1866
nithinpes
410 Expert 256MB
Hi Guys, I am a beginner to perl.
I need a perl package which will perform basic DB operations like select , insert,update,delete operation MySql DB.

i Have a Mysql DB which resides on my local machine.DB Deatils are :
Localhost,MySql,DatabaseName:perltest, username:root,pwd:sierra,table:samples with coulms :id,name,phone

I am done with selecting the rows in DB. I need Sample code for inserting , updating and deleting . Please provide some basic infor regarding these.

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl -w 
  2.  
  3. use DBI; 
  4.  
  5. $dbh = DBI->connect('dbi:mysql:perltest','root','sierra') 
  6.  
  7. or die "Connection Error: $DBI::errstr\n"; 
  8.  
  9. $sql = "select * from samples"; 
  10.  
  11. $sth = $dbh->prepare($sql); 
  12.  
  13. $sth->execute 
  14.  
  15. or die "SQL Error: $DBI::errstr\n"; 
  16.  
  17. while (@row = $sth->fetchrow_array) { 
  18.  
  19. print "@row\n"; 
  20.  
  21. }
  22.  
Similarly i Need code for Inserting and updating and deleting operations and all these functions as a package. Can guyz help me in how to proceed for these things.

You can mail me ur proceeding to this id EMAILS REMOVED

Thanks in Advance
Koti.
The examples will be available in the documentation for DBD::MySQL in search.cpan.org.
You may go through this link
Oct 29 '08 #2
numberwhun
3,509 Expert Mod 2GB
Please DO NOT include any email addresses or contact information in the technical forums. This information is easily scraped by web spiders. This policy exists for your protection. Please read the Posting Guidelines for this site so you are aware of what to and not to do.

Regards,

Moderator
Oct 29 '08 #3
Icecrack
174 Expert 100+
well first off this question isn't related to Perl, but to mysql statements

for example look at the var $sql see what has changed from the code you posted.
Expand|Select|Wrap|Line Numbers
  1. use DBI; 
  2.  
  3. $dbh = DBI->connect('dbi:mysql:perltest','root','sierra') 
  4.  
  5. or die "Connection Error: $DBI::errstr\n"; 
  6.  
  7. $sql = "INSERT INTO $tablename (custid, name, repcode, state, contact, phone, warn) VALUES ('$customerid','$customername','$repcode','$state','$contact','$tel','$warnnote') "; 
  8.  
  9. $sth = $dbh->prepare($sql); 
  10.  
  11. $sth->execute 
  12.  
  13. or die "SQL Error: $DBI::errstr\n"; 
Oct 30 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

15
by: Jack | last post by:
I have a text file of data in a file (add2db.txt) where the entries are already entered on separate lines in the following form: INSERT INTO `reviews` VALUES("", "Tony's", "Lunch", "Great...
2
by: Atz | last post by:
Hi to all ! Im using MySql front and PHP 5 for some web shop. I didn't try it so far but i guess that the online data insertation ( accept costs and time ) should be the same process like for...
3
by: Pugi! | last post by:
On a freshly installed Fedora C3 (incl. webserver apache php mysql) i get the following problem when connecting to mysql through a browser (phpMyAdmin): : #2002 Can't connect to local MySQL...
16
by: MLH | last post by:
Using MS Access, I have attached to MySQL servers in other states and other countries on the other side of my router. But when I use the MySQL ODBC driver 3.51 to connect to a MySQL server on my...
4
by: Ian Davies | last post by:
Hello all The following code allows me to connect to a local MySQL database on my pc from a VB6 project. **************************************************************************** ** Dim...
7
by: phillip.s.powell | last post by:
We're looking at a GUI interface for our MySQL DB and I am interested in MySQL Administrator, however, one of our requirements is to be able to import/export databases. Is this possible or do I...
2
by: bballr | last post by:
I have a problem that I'm not sure if it can be done. I'm trying to use the MySQL C API to be able to use a normal sql insert statement that will send the data or file to a directory and NOT the...
11
by: refugeedeveloper | last post by:
Im trying to use the mysql_connect command to connect to the mysql server from a php file. What is the HOST name I should use? The tutorial book I have uses "localhost" but Im installing the...
2
josie23
by: josie23 | last post by:
Egad, I'm not a coder/programmer by nature or occupation but understand things like html and css and a small amount of perl. So, basically, I'm a perl/mysql imbecile. But, I've been trying to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.