dbi

MySQL connection not working from within Perl CGI script

时光总嘲笑我的痴心妄想 提交于 2019-12-06 06:11:51
I can easily connect to a remote MySQL server using the DBI module in my Perl scripts. However, when I try to use the same connection settings/properties from within a CGI script, the connection fails. There are no helpful errors/warnings being logged either in the apache error log, or the browser, in spite of using use CGI::Carp qw(warningsToBrowser fatalsToBrowser); Strangely, the exact same script works fine when executed from the terminal. I also tried connecting the CGI script to the MySQL server on localhost, but without any success. On the other hand, phpMyAdmin works great on the

Where to put ruby .gem files so that Shoes.setup can find them?

女生的网名这么多〃 提交于 2019-12-05 17:54:31
A lot of questions have been asked about gem support in Shoes, but none have answered where to put them. I've got Shoes Raisins 1134 on Windows XP, and I've downloaded dbi-0.4.1.gem and am trying to get the following to work: Shoes.setup do gem 'dbi' end require 'dbi' Shoes.app ... end When I run this, I get the dialog that says Installing dbi -- Looking for dbi which sits for hours not finding the gem file. I've tried putting it in all of the following places to no avail: The folder that contains the above script D:\Program Files\Common Files\Shoes\0.r1134\ruby\gems D:\Program Files\Common

Automatic character encoding handling in Perl / DBI / DBD::ODBC

血红的双手。 提交于 2019-12-05 16:53:14
I'm using Perl with DBI / DBD::ODBC to retrieve data from an SQL Server database, and have some issues with character encoding. The database has a default collation of SQL_Latin1_General_CP1_CI_AS , so data in varchar columns is encoded in Microsoft's version of Latin-1, AKA windows-1252 . There doesn't seem to be a way to handle this transparently in DBI/DBD::ODBC. I get data back still encoded as windows-1252 , for instance, € “ ” are encoded as bytes 0x80, 0x93 and 0x94. When I write those to an UTF-8 encoded XML file without decoding them first, they are written as Unicode characters 0x80,

DBI database handle with AutoCommit set to 0 not returning proper data with SELECT?

拈花ヽ惹草 提交于 2019-12-05 15:41:49
问题 This is a tricky one to explain (and very weird), so bear with me. I will explain the problem, and the fix for it, but I would like to see if anyone can explain why it works the way it works :) I have a web application that uses mod_perl. It uses MySQL database, and I am writing data to a database on regular basis. It is modular, so it also has its own 'database' type of a module, where I handle connection, updates, etc. database::db_connect() subroutine is used to connect to database, and

how to query sqlite for certain rows, i.e. dividing it into pages (perl DBI)

妖精的绣舞 提交于 2019-12-05 10:16:24
sorry for my noob question, I'm currently writing a perl web application with sqlite database behind it. I would like to be able to show in my app query results which might get thousands of rows - these should be split in pages - routing should be like /webapp/N - where N is the page number. what is the correct way to query the sqlite db using DBI, in order to fetch only the relavent rows. for instance, if I show 25 rows per page so I want to query the db for 1-25 rows in the first page, 26-50 in the second page etc.... Using the LIMIT / OFFSET construction will show pages, but the OFFSET

How do I get schemas from Perl's DBI?

 ̄綄美尐妖づ 提交于 2019-12-05 07:28:01
I am using Perl DBI . I know that $dbase->tables() will return all the tables in the corresponding database. Likewise, I want to know the schemas available in the database. Is there any function available for that? What you're looking for is: DBI->table_info() Call it like this: my $sth = $dbh->table_info('', '%', ''); my $schemas = $dbh->selectcol_arrayref($sth, {Columns => [2]}); print "Schemas: ", join ', ', @$schemas; This works. Create a database: echo 'create table foo (bar integer primary key, quux varchar(30));' | sqlite3 foobar.sqlite Perl program to print schema: use 5.010; use Data:

How do I tell DBD::mysql where mysql.sock is?

爷,独闯天下 提交于 2019-12-05 04:20:29
Using DBD::mysql with DBI, I am getting the following error when attempting to connect to the database. DBI connect('database=mydb:host=localhost','someuser',...) failed: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) at ./myscript.pl line 97 Yes MySQL is up and running. The problem is that mysql.sock is not in /tmp. I know the location of mysql.sock and I currently have it hacked so that it works, I created a soft link to the current location of the mysql.sock file. I would rather not change the MySQL configuration, though this would probably be the easiest thing to

How can I handle unicode with Perl's DBI?

∥☆過路亽.° 提交于 2019-12-04 22:48:00
My delicious-to-wp perl script works but gives for all "weird" characters even weirder output. So I tried $description = decode_utf8( $description ); but that doesnt make a difference. I would like e.g. “go live” to become “go live” and not “go live†How can I handle unicode in Perl so that this works? UPDATE: I found the problem was to set utf of DBI I had to set in Perl: my $sql = qq{SET NAMES 'utf8';}; $dbh->do($sql); That was the part that I had to set, tricky. Thanks! It may have nothing to do with Perl. Check to make sure you're using UTF encodings in the pertinent MySQL table columns

should I commit in the following code?

丶灬走出姿态 提交于 2019-12-04 21:39:01
My code: 122 # 123 my $hfpDbh = undef; 124 unless ( 125 $hfpDbh = DBI->connect("dbi:Pg:host=....")#removed something 128 ) { 129 Log( ERROR, "" ); 130 Exit( 1 ) 131 } 132 $hfpDbh->{RaiseError} = 1; 133 $hfpDbh->{AutoCommit} = 0; 134 135 ( my $mydata, $msg ) = load_data( $hfpDbh, $DatFile ); 136 unless ( defined($mydata) ) 137 { 138 Log(INFO, "Calling exit...2"); 139 } 140 #$hfpDbh->disconnect(); 141 Exit( 0 ); 142 Log(INFO, "Calling exit...4"); 143 144 145 sub load_data 146 { 147 my ( $dbh, $DatFile ) = @_; 148 my $msg = ''; 149 unless ( $dbh ) { 150 $msg = 'cannot load data, no DB handle';

DBI: raiseerror in eval

对着背影说爱祢 提交于 2019-12-04 15:51:39
This question refers to this comment from Ikegami: [...] But if you're going to put an eval around every statement, just use RaiseError => 0. [...] in this thread . What do I gain, if I set RaiseError to 0 in such situations? #!/usr/bin/env perl use warnings; use 5.10.1; use DBI; my $db = 'my_test_sqlite_db.sqlite'; open my $fh, '>', $db or die $!; close $fh or die $!; my ( $dbh, $sth ); eval { $dbh = DBI->connect( "DBI:SQLite:dbname=$db", "", "", {} ); }; if ( $@ ) { print $@ }; my $table = 'my_sqlite_table'; say "RaiseError = 1"; say "PrintError = 0"; $dbh->{RaiseError} = 1; $dbh->