mysql_insertid not working!!!

mysql_insertid not working!!!

am 29.03.2004 16:33:54 von atif

hello every body!!!

I want to fetch the rowid/rowcount when I insert some data in the table; I mean the row# where data has been inserted

I have tried all of these after connecting the data base...
here is my code.....


use DBI;
use DBD::mysql;

$dbh=$DBI->connect("DBI:mysql:database=asteriskvmusers:local host","root","vmuser");

$rth=$dbh->prepare("insert into users () values('test','1037','4366','test2 test2','test2@test2.com','','','')");
$rth->execute();

$row_id1 = $rth->{mysql_insertid};**

$rth->finish();


**I have also tried $rth->{'mysql_insertid'}
but it always returns 0 (zero)

please smbdy sort it out

Thankyou


--
Atif Rasheed
Convergence (Business Systems)
http://www.convergence.com.pk
--

--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules@m .gmane.org

Re: mysql_insertid not working!!!

am 29.03.2004 16:54:53 von Rudy Lippan

On Mon, 29 Mar 2004, atif wrote:

> use DBI;
> use DBD::mysql;
>
>
> $dbh=$DBI->connect("DBI:mysql:database=asteriskvmusers:local host","root","vmuser");
>
> $rth=$dbh->prepare("insert into users ()
> values('test','1037','4366','test2 test2','test2@test2.com','','','')");
> $rth->execute();


You are not checking return values & you do not have raise error set, so
how do you kow that the prepare/execute worked?


Rudy


--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules@m .gmane.org

Re: mysql_insertid not working!!!

am 29.03.2004 16:54:53 von Rudy Lippan

On Mon, 29 Mar 2004, atif wrote:

> use DBI;
> use DBD::mysql;
>
>
> $dbh=$DBI->connect("DBI:mysql:database=asteriskvmusers:local host","root","vmuser");
>
> $rth=$dbh->prepare("insert into users ()
> values('test','1037','4366','test2 test2','test2@test2.com','','','')");
> $rth->execute();


You are not checking return values & you do not have raise error set, so
how do you kow that the prepare/execute worked?


Rudy


--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules@m .gmane.org

Re: mysql_insertid not working!!!

am 30.03.2004 07:44:48 von atif

prepare/execute is working, becaz I am watching the database, all the rows I inserted through the script are there in the database...

--
Atif Rasheed
Convergence (Business Systems)
http://www.convergence.com.pk
--

--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules@m .gmane.org

Re: mysql_insertid not working!!!

am 30.03.2004 07:44:48 von atif

prepare/execute is working, becaz I am watching the database, all the rows I inserted through the script are there in the database...

--
Atif Rasheed
Convergence (Business Systems)
http://www.convergence.com.pk
--

--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules@m .gmane.org

Re: mysql_insertid not working!!!

am 30.03.2004 08:04:51 von David Dick

g'day atif,

it is very difficult for me to get the results you got from the example
you have supplied.

Can you supply the table structure of "users" so we can run this code
and duplicate your experience?

eg.

#! /usr/bin/perl -wT

use DBI();
use strict;

my ($dbh) =
DBI->connect("DBI:mysql:database=stockcontrol;host=local.ope nsoftware.com.au","stockcontrol","stockcontrol",
{ 'RaiseError' => 1 });

my ($sth);
$sth = $dbh->prepare("create table users_1 ( user_id int not null
auto_increment primary key, user_name char(10) not null, num_1 int,
num_2 int, long_name varchar(50), email varchar(50))");
$sth->execute();
$sth->finish();
$sth = $dbh->prepare("insert into users_1 (user_name, num_1, num_2,
long_name, email) values('test','1037','4366','test2
test2','test2\@test2.com')");
$sth->execute();

my ($row_id1) = $sth->{mysql_insertid};
print "Row:$row_id1\n";

$sth->finish();

$sth = $dbh->prepare("drop table users_1");
$sth->execute();
$sth->finish();

$dbh->disconnect();



atif wrote:
> hello every body!!!
>
> I want to fetch the rowid/rowcount when I insert some data in the table; I mean the row# where data has been inserted
>
> I have tried all of these after connecting the data base...
> here is my code.....
>
>
> use DBI;
> use DBD::mysql;
>
> $dbh=$DBI->connect("DBI:mysql:database=asteriskvmusers:local host","root","vmuser");
>
> $rth=$dbh->prepare("insert into users () values('test','1037','4366','test2 test2','test2@test2.com','','','')");
> $rth->execute();
>
> $row_id1 = $rth->{mysql_insertid};**
>
> $rth->finish();
>
>
> **I have also tried $rth->{'mysql_insertid'}
> but it always returns 0 (zero)
>
> please smbdy sort it out
>
> Thankyou
>
>
> --
> Atif Rasheed
> Convergence (Business Systems)
> http://www.convergence.com.pk
> --
>

--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules@m .gmane.org

Re: mysql_insertid not working!!!

am 30.03.2004 08:04:51 von David Dick

g'day atif,

it is very difficult for me to get the results you got from the example
you have supplied.

Can you supply the table structure of "users" so we can run this code
and duplicate your experience?

eg.

#! /usr/bin/perl -wT

use DBI();
use strict;

my ($dbh) =
DBI->connect("DBI:mysql:database=stockcontrol;host=local.ope nsoftware.com.au","stockcontrol","stockcontrol",
{ 'RaiseError' => 1 });

my ($sth);
$sth = $dbh->prepare("create table users_1 ( user_id int not null
auto_increment primary key, user_name char(10) not null, num_1 int,
num_2 int, long_name varchar(50), email varchar(50))");
$sth->execute();
$sth->finish();
$sth = $dbh->prepare("insert into users_1 (user_name, num_1, num_2,
long_name, email) values('test','1037','4366','test2
test2','test2\@test2.com')");
$sth->execute();

my ($row_id1) = $sth->{mysql_insertid};
print "Row:$row_id1\n";

$sth->finish();

$sth = $dbh->prepare("drop table users_1");
$sth->execute();
$sth->finish();

$dbh->disconnect();



atif wrote:
> hello every body!!!
>
> I want to fetch the rowid/rowcount when I insert some data in the table; I mean the row# where data has been inserted
>
> I have tried all of these after connecting the data base...
> here is my code.....
>
>
> use DBI;
> use DBD::mysql;
>
> $dbh=$DBI->connect("DBI:mysql:database=asteriskvmusers:local host","root","vmuser");
>
> $rth=$dbh->prepare("insert into users () values('test','1037','4366','test2 test2','test2@test2.com','','','')");
> $rth->execute();
>
> $row_id1 = $rth->{mysql_insertid};**
>
> $rth->finish();
>
>
> **I have also tried $rth->{'mysql_insertid'}
> but it always returns 0 (zero)
>
> please smbdy sort it out
>
> Thankyou
>
>
> --
> Atif Rasheed
> Convergence (Business Systems)
> http://www.convergence.com.pk
> --
>

--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules@m .gmane.org

Re: mysql_insertid not working!!!

am 30.03.2004 08:18:30 von atif

Thankyou David....
here is the table structure...


Database: asteriskvmusers Table: users Rows: 47
+----------+---------------+------+-----+---------+-------+- --------------------------------+
| Field | Type | Null | Key | Default | Extra | Privileges |
+----------+---------------+------+-----+---------+-------+- --------------------------------+
| context | char(79) | | PRI | | | select,insert,update,references |
| mailbox | char(79) | | PRI | | | select,insert,update,references |
| password | char(79) | | | | | select,insert,update,references |
| fullname | char(79) | | | | | select,insert,update,references |
| email | char(79) | | | | | select,insert,update,references |
| pager | char(79) | | | | | select,insert,update,references |
| options | char(159) | | | | | select,insert,update,references |
| stamp | timestamp(14) | YES | | | | select,insert,update,references |
+----------+---------------+------+-----+---------+-------+- --------------------------------+


--
Atif Rasheed
Convergence (Business Systems)
http://www.convergence.com.pk
--

--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules@m .gmane.org

Re: mysql_insertid not working!!!

am 30.03.2004 08:18:30 von atif

Thankyou David....
here is the table structure...


Database: asteriskvmusers Table: users Rows: 47
+----------+---------------+------+-----+---------+-------+- --------------------------------+
| Field | Type | Null | Key | Default | Extra | Privileges |
+----------+---------------+------+-----+---------+-------+- --------------------------------+
| context | char(79) | | PRI | | | select,insert,update,references |
| mailbox | char(79) | | PRI | | | select,insert,update,references |
| password | char(79) | | | | | select,insert,update,references |
| fullname | char(79) | | | | | select,insert,update,references |
| email | char(79) | | | | | select,insert,update,references |
| pager | char(79) | | | | | select,insert,update,references |
| options | char(159) | | | | | select,insert,update,references |
| stamp | timestamp(14) | YES | | | | select,insert,update,references |
+----------+---------------+------+-----+---------+-------+- --------------------------------+


--
Atif Rasheed
Convergence (Business Systems)
http://www.convergence.com.pk
--

--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules@m .gmane.org

Re: mysql_insertid not working!!!

am 30.03.2004 08:22:19 von atif

and here is my script.....

#!/usr/bin/perl

use Asterisk::AGI;
$AGI = new Asterisk::AGI;
%input = $AGI->ReadParse();

use DBI;
use DBD::mysql;

my $drh=DBI->install_driver('mysql');

$dbh=$drh->connect("DBI:mysql:database=asteriskvmusers:local host","root","vmuser");

$rth=$dbh->prepare("insert into users () values('test','1039','4366','test2 test2','test2@test2.com','','','')");
$rth->execute();
$row_id1 = $rth->{mysql_insertid};
$rth->finish();

$sth=$dbh->prepare("insert into users () values ('test','1040','4366','test2 test2','test2@test2.com','','','')");
$sth->execute();
$row_id2 = $sth->{'mysql_insertid'};

$sth->finish();

$test = 500;

$dbh->disconnect;

print "rowid1 obtained from mysql_insert_id = $row_id1\n";
print "rowid2 obtained from mysql_insert_id = $row_id2\n";
print "test variable = $test\n";


--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules@m .gmane.org

Re: mysql_insertid not working!!!

am 30.03.2004 08:22:19 von atif

and here is my script.....

#!/usr/bin/perl

use Asterisk::AGI;
$AGI = new Asterisk::AGI;
%input = $AGI->ReadParse();

use DBI;
use DBD::mysql;

my $drh=DBI->install_driver('mysql');

$dbh=$drh->connect("DBI:mysql:database=asteriskvmusers:local host","root","vmuser");

$rth=$dbh->prepare("insert into users () values('test','1039','4366','test2 test2','test2@test2.com','','','')");
$rth->execute();
$row_id1 = $rth->{mysql_insertid};
$rth->finish();

$sth=$dbh->prepare("insert into users () values ('test','1040','4366','test2 test2','test2@test2.com','','','')");
$sth->execute();
$row_id2 = $sth->{'mysql_insertid'};

$sth->finish();

$test = 500;

$dbh->disconnect;

print "rowid1 obtained from mysql_insert_id = $row_id1\n";
print "rowid2 obtained from mysql_insert_id = $row_id2\n";
print "test variable = $test\n";


--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules@m .gmane.org

Re: mysql_insertid not working!!!

am 30.03.2004 11:20:47 von David Dick

G'day atif,

the problem is that your table does not have an auto_increment field
defined.

http://www.mysql.com/doc/en/example-AUTO_INCREMENT.html

uru
-dave


atif wrote:
> Thankyou David....
> here is the table structure...
>
>
> Database: asteriskvmusers Table: users Rows: 47
> +----------+---------------+------+-----+---------+-------+- --------------------------------+
> | Field | Type | Null | Key | Default | Extra | Privileges |
> +----------+---------------+------+-----+---------+-------+- --------------------------------+
> | context | char(79) | | PRI | | | select,insert,update,references |
> | mailbox | char(79) | | PRI | | | select,insert,update,references |
> | password | char(79) | | | | | select,insert,update,references |
> | fullname | char(79) | | | | | select,insert,update,references |
> | email | char(79) | | | | | select,insert,update,references |
> | pager | char(79) | | | | | select,insert,update,references |
> | options | char(159) | | | | | select,insert,update,references |
> | stamp | timestamp(14) | YES | | | | select,insert,update,references |
> +----------+---------------+------+-----+---------+-------+- --------------------------------+
>
>
> --
> Atif Rasheed
> Convergence (Business Systems)
> http://www.convergence.com.pk
> --
>

--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules@m .gmane.org

Re: mysql_insertid not working!!!

am 30.03.2004 11:20:47 von David Dick

G'day atif,

the problem is that your table does not have an auto_increment field
defined.

http://www.mysql.com/doc/en/example-AUTO_INCREMENT.html

uru
-dave


atif wrote:
> Thankyou David....
> here is the table structure...
>
>
> Database: asteriskvmusers Table: users Rows: 47
> +----------+---------------+------+-----+---------+-------+- --------------------------------+
> | Field | Type | Null | Key | Default | Extra | Privileges |
> +----------+---------------+------+-----+---------+-------+- --------------------------------+
> | context | char(79) | | PRI | | | select,insert,update,references |
> | mailbox | char(79) | | PRI | | | select,insert,update,references |
> | password | char(79) | | | | | select,insert,update,references |
> | fullname | char(79) | | | | | select,insert,update,references |
> | email | char(79) | | | | | select,insert,update,references |
> | pager | char(79) | | | | | select,insert,update,references |
> | options | char(159) | | | | | select,insert,update,references |
> | stamp | timestamp(14) | YES | | | | select,insert,update,references |
> +----------+---------------+------+-----+---------+-------+- --------------------------------+
>
>
> --
> Atif Rasheed
> Convergence (Business Systems)
> http://www.convergence.com.pk
> --
>

--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules@m .gmane.org

Re: mysql_insertid not working!!!

am 30.03.2004 15:42:06 von atif

Thanks David:)

it worked...


--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules@m .gmane.org

Re: mysql_insertid not working!!!

am 30.03.2004 15:42:06 von atif

Thanks David:)

it worked...


--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules@m .gmane.org