Retrieving an Index ID : MySql « Database « Perl

Home
Perl
1.Array
2.CGI
3.Class
4.Data Type
5.Database
6.File
7.GUI
8.Hash
9.Language Basics
10.Network
11.Regular Expression
12.Report
13.Statement
14.String
15.Subroutine
16.System Functions
17.Win32
18.XML
Perl » Database » MySql 
Retrieving an Index ID
   


#!/usr/bin/perl

use DBI;
use strict;

my $username = "dbuser";
my $password = "dbpassword";
my $dsn = "dbi:mysql:goo:192.168.1.10";

my $dbh = DBI->connect($dsn,$username,$passwordor die "Cannot connect to database: $DBI::errstr";

my $sth = $dbh->prepare("INSERT INTO urls VALUES('','http://www.demo.org/','suehring',unix_timestamp(),'query words')");

$sth->execute() or die "Cannot execute sth: $DBI::errstr";

my $insertid = $dbh->{'mysql_insertid'};
print "$insertid\n";

$dbh->disconnect();

   
    
    
  
Related examples in the same category
1.Deleting Entries
2.Dumping a Query's Results
3.Error Diagnostic Variables
4.Handling Quotes
5.Inserting into a Database
6.Load text file to database
7.MySQL Data Types
8.Preparing a Statement Handle and Fetching Results
9.Pushing Query Results to an Array to Find Wildcard Hosts
10.Query parameter binding
11.Retrieving Query Results Listing MySQL Users and Hosts
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.