develooper Front page | perl.dbi.users | Postings from September 2018

Tim Bunce - RE: DBD-DBI Insert Binary Files and using Perl modulesin cPanel environment

Thread Next
From:
Kimar Miller
Date:
September 28, 2018 02:47
Subject:
Tim Bunce - RE: DBD-DBI Insert Binary Files and using Perl modulesin cPanel environment
Message ID:
CAPk6REXtEPSjYKj_8se6CDJg9TejGvtqeZnOXKS=EsjJ+YAo8Q@mail.gmail.com
´╗┐none of the tests were able to add a value pair set to the database. They did execute but no real data was submited. The perl results were shown as the name of the file selected but no real insert. Looking in the database with PHPmyAdmin I feel embarrassed. I didn't see any real results.

worked

#!/usr/bin/perlml -wT
use cPanelUserConfig;
use CGI;
use warnings;
use strict;
use DBI;
use utf8;
my $q= new CGI;
print $q->header("text/plain");

my $dsn= "dbi:mysql:database=video;mysql_enable_utf8mb4=1";
# ;mysql_enable_utf8mb4=1 tells the perl server that the mysql utf must be enabled for use
my $user= "test";
my $pass= 'password';
my ($dbh, $sth, @row);

    $dbh= DBI->connect($dsn, $user, $pass, { PrintError => 0, RaiseError => 1, AutoCommit => 0 } ) or die "Cannot Connect: ".$DBI::errstr;
    
print "These are the results received\n";

my ($name, $value, @std, $num);

$num=0;
foreach $name ($q->param) {
    
	print "$name: ";

	foreach $value ($q->param($name) ) {
        $std[$num]= $value;
		print "$value\n";
        $num= $num+1;
	}

}

    print "DB Connect Attempted...<br>\n";
    
    #$q->$cgi->upload("file");
    
	$sth= $dbh->prepare("insert into video (name, description, blobfile) values ($std[0], $std[1], $std[2])") or die "Error due to - $dbh->errstr";
	#do statement can not be used with driver support placeholders hence the prepare statement must be used
    $sth->execute($q->param("upload_file")) or die "Error due to - $dbh->errstr";
    
    print "Statement Handle Executed...";
    
    $sth->finish();
    $dbh->disconnect();
    
exit;

worked

#!/usr/bin/perlml -wT
use cPanelUserConfig;
use CGI;
use warnings;
use strict;
use DBI;
use utf8;
my $q= new CGI;
print $q->header("text/plain");

my $dsn= "dbi:mysql:database=video;mysql_enable_utf8mb4=1";
# ;mysql_enable_utf8mb4=1 tells the perl server that the mysql utf must be enabled for use
my $user= "test";
my $pass= 'password';
my ($dbh, $sth, @row);

    $dbh= DBI->connect($dsn, $user, $pass, { PrintError => 0, RaiseError => 1, AutoCommit => 0 } ) or die "Cannot Connect: ".$DBI::errstr;
    
print "These are the results received\n";

my ($name, $value, @std, $num);

$num=0;
foreach $name ($q->param) {
    
	print "$name: ";

	foreach $value ($q->param($name) ) {
        $std[$num]= $value;
		print "$value\n";
        $num= $num+1;
	}

}

    print "DB Connect Attempted...<br>\n";
    
    #$q->$cgi->upload("file");
    
	$sth= $dbh->prepare("insert into video (name, description, blobfile) values ($std[0], $std[1], $std[2])") or die "Error due to - $dbh->errstr";
	#do statement can not be used with driver support placeholders hence the prepare statement must be used
    $sth->execute(my $cgi->param("upload_file")) or die "Error due to - $dbh->errstr";
    
    print "Statement Handle Executed...";
    
    $sth->finish();
    $dbh->disconnect();
    
exit;

worked

#!/usr/bin/perlml -wT
use cPanelUserConfig;
use CGI;
use warnings;
use strict;
use DBI;
use utf8;
my $q= new CGI;
print $q->header("text/plain");

my $dsn= "dbi:mysql:database=video;mysql_enable_utf8mb4=1";
# ;mysql_enable_utf8mb4=1 tells the perl server that the mysql utf must be enabled for use
my $user= "test";
my $pass= 'password';
my ($dbh, $sth, @row);

    $dbh= DBI->connect($dsn, $user, $pass, { PrintError => 0, RaiseError => 1, AutoCommit => 0 } ) or die "Cannot Connect: ".$DBI::errstr;
    
print "These are the results received\n";

my ($name, $value, @std, $num);

$num=0;
foreach $name ($q->param) {
    
	print "$name: ";

	foreach $value ($q->param($name) ) {
        $std[$num]= $value;
		print "$value\n";
        $num= $num+1;
	}

}

    print "DB Connect Attempted...<br>\n";
    my $cgi->param("upload_file");
    #$q->$cgi->upload("file");
    
	$sth= $dbh->prepare("insert into video (name, description, blobfile) values ($std[0], $std[1], $std[2])") or die "Error due to - $dbh->errstr";
	#do statement can not be used with driver support placeholders hence the prepare statement must be used
    $sth->execute() or die "Error due to - $dbh->errstr";
    
    print "Statement Handle Executed...";
    
    $sth->finish();
    $dbh->disconnect();
    
exit;

worked

#!/usr/bin/perlml -wT
use cPanelUserConfig;
use CGI;
use warnings;
use strict;
use DBI;
use utf8;
my $q= new CGI;
print $q->header("text/plain");

my $dsn= "dbi:mysql:database=video;mysql_enable_utf8mb4=1";
# ;mysql_enable_utf8mb4=1 tells the perl server that the mysql utf must be enabled for use
my $user= "test";
my $pass= 'password';
my ($dbh, $sth, @row);

    $dbh= DBI->connect($dsn, $user, $pass, { PrintError => 0, RaiseError => 1, AutoCommit => 0 } ) or die "Cannot Connect: ".$DBI::errstr;
    
print "These are the results received\n";

my ($name, $value, @std, $num);

$num=0;
foreach $name ($q->param) {
    
	print "$name: ";

	foreach $value ($q->param($name) ) {
        $std[$num]= $value;
		print "$value\n";
        $num= $num+1;
	}

}

    print "DB Connect Attempted...<br>\n";
    
    $q->upload("file");
	$sth= $dbh->prepare("insert into video (name, description, blobfile) values (?,?,?)") or die "Error due to - $dbh->errstr";
	#do statement can not be used with driver support placeholders hence the prepare statement must be used
    $sth->execute($std[0], $std[1], $std[2]) or die "Error due to - $dbh->errstr";
    
    $sth->finish();
    $dbh->disconnect();
    
exit;

worked

#!/usr/bin/perlml -wT
use cPanelUserConfig;
use CGI;
use warnings;
use strict;
use DBI;
use utf8;
my $q= new CGI;
print $q->header("text/plain");

my $dsn= "dbi:mysql:database=video;mysql_enable_utf8mb4=1";
# ;mysql_enable_utf8mb4=1 tells the perl server that the mysql utf must be enabled for use
my $user= "test";
my $pass= 'password';
my ($dbh, $sth, @row);

    $dbh= DBI->connect($dsn, $user, $pass, { PrintError => 0, RaiseError => 1, AutoCommit => 0 } ) or die "Cannot Connect: ".$DBI::errstr;
    
print "These are the results received\n";

my ($name, $value, @std, $num);

$num=0;
foreach $name ($q->param) {
    
	print "$name: ";

	foreach $value ($q->param($name) ) {
        $std[$num]= $value;
		print "$value\n";
        $num= $num+1;
	}
	print "$std[0], $std[1], $std[2]";
}
    $q->upload("file");

    
    print "DB Connect Attempted...<br>\n";

	$sth= $dbh->prepare("insert into video (name, description, blobfile) values ($std[0], $std[1], $std[2])") or die "Error due to - $dbh->errstr";
	#do statement can not be used with driver support placeholders hence the prepare statement must be used
    $sth->execute() or die "Error due to - $dbh->errstr";
    
    $sth->finish();
    $dbh->disconnect();
    
exit;

worked


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About