<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>OpenText Analytics Database 26.2.x – Connecting to OpenText&amp;trade; Analytics Database using Perl</title>
    <link>/en/connecting-to/client-libraries/accessing/perl/connecting-to-using-perl/</link>
    <description>Recent content in Connecting to OpenText&amp;trade; Analytics Database using Perl on OpenText Analytics Database 26.2.x</description>
    <generator>Hugo -- gohugo.io</generator>
    
	  <atom:link href="/en/connecting-to/client-libraries/accessing/perl/connecting-to-using-perl/index.xml" rel="self" type="application/rss+xml" />
    
    
      
        
      
    
    
    <item>
      <title>Connecting-To: Setting ODBC connection parameters in Perl</title>
      <link>/en/connecting-to/client-libraries/accessing/perl/connecting-to-using-perl/setting-odbc-connection-parameters-perl/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/connecting-to/client-libraries/accessing/perl/connecting-to-using-perl/setting-odbc-connection-parameters-perl/</guid>
      <description>
        
        
        &lt;p&gt;To set ODBC connection parameters, replace the DSN name with a semicolon delimited list of parameter name and value pairs in the source data string. Use the DSN parameter to tell DBD::ODBC which DSN to use, then add in other the other ODBC parameters you want to set. For example, the following code connects using a DSN named VerticaDSN and sets the connection&#39;s locale to en_GB.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;#!/usr/bin/perl -w
use strict;
use DBI;
# Instead of just using the DSN name, use name and value pairs.
my $dbh = DBI-&amp;gt;connect(&amp;#34;dbi:ODBC:DSN=VerticaDSN;Locale=en_GB@collation=binary&amp;#34;,&amp;#34;ExampleUser&amp;#34;,&amp;#34;password123&amp;#34;);
unless (defined $dbh) {
    # Conection failed.
    die &amp;#34;Failed to connect: $DBI::errstr&amp;#34;;
}
print &amp;#34;Connected!\n&amp;#34;;
$dbh-&amp;gt;disconnect();
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;See &lt;a href=&#34;../../../../../../en/connecting-to/client-libraries/client-drivers/install-config/odbc/creating-an-odbc-data-source-name-dsn/odbc-dsn-connection-properties/#&#34;&gt;ODBC DSN connection properties&lt;/a&gt; for a list of the connection parameters you can set in the source data string.&lt;/p&gt;

      </description>
    </item>
    
    <item>
      <title>Connecting-To: Setting Perl DBI connection attributes</title>
      <link>/en/connecting-to/client-libraries/accessing/perl/connecting-to-using-perl/setting-perl-dbi-connection-attributes/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/connecting-to/client-libraries/accessing/perl/connecting-to-using-perl/setting-perl-dbi-connection-attributes/</guid>
      <description>
        
        
        &lt;p&gt;The Perl DBI module has attributes that you can use to control the behavior of its database connection. These attributes are similar to the ODBC connection parameters (in several cases, they duplicate each other&#39;s functionality). The DBI connection attributes are a cross-platform way of controlling the behavior of the database connection.&lt;/p&gt;
&lt;p&gt;You can set the DBI connection attributes when establishing a connection by passing the DBI &lt;code&gt;connect&lt;/code&gt; function a hash containing attribute and value pairs. For example, to set the DBI connection attribute AutoCommit to false, you would use:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;# Create a hash that holds attributes for the connection
my $attr = {AutoCommit =&amp;gt; 0};
# Open a connection using a DSN. Supply the username and password.
my $dbh = DBI-&amp;gt;connect(&amp;#34;dbi:ODBC:VerticaDSN&amp;#34;,&amp;#34;ExampleUser&amp;#34;,&amp;#34;password123&amp;#34;,
    $attr);
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;See the DBI documentation&#39;s &lt;a href=&#34;http://search.cpan.org/~timb/DBI/DBI.pm#ATTRIBUTES_COMMON_TO_ALL_HANDLES&#34;&gt;Database Handle Attributes&lt;/a&gt; section for a full description of the attributes you can set on the database connection.&lt;/p&gt;
&lt;p&gt;After your script has connected, it can access and modify the connection attributes through the database handle by using it as a hash reference. For example:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;print &amp;#34;The AutoCommit attribute is: &amp;#34; . $dbh-&amp;gt;{AutoCommit} . &amp;#34;\n&amp;#34;;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The following example demonstrates setting two connection attributes:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;RaiseError controls whether the DBI driver generates a Perl error if it encounters a database error. Usually, you set this to true (1) if you want your Perl script to exit if there is a database error.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;AutoCommit controls whether statements automatically commit their transactions when they complete. DBI defaults to OpenText™ Analytics Database&#39;s default AutoCommit value of true. Always set AutoCommit to false (0) when bulk loading data to increase database efficiency.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;#!/usr/bin/perl
use strict;
use DBI;
# Create a hash that holds attributes for the connection
 my $attr = {
                RaiseError =&amp;gt; 1, # Make database errors fatal to script
                AutoCommit =&amp;gt; 0, # Prevent statements from committing
                                 # their transactions.
            };
# Open a connection using a DSN. Supply the username and password.
my $dbh = DBI-&amp;gt;connect(&amp;#34;dbi:ODBC:VerticaDSN&amp;#34;,&amp;#34;ExampleUser&amp;#34;,&amp;#34;password123&amp;#34;,
    $attr);

if (defined $dbh-&amp;gt;err) {
    # Connection failed.
    die &amp;#34;Failed to connect: $DBI::errstr&amp;#34;;
}
print &amp;#34;Connected!\n&amp;#34;;
# The database handle lets you access the connection attributes directly:
print &amp;#34;The AutoCommit attribute is: &amp;#34; . $dbh-&amp;gt;{AutoCommit} . &amp;#34;\n&amp;#34;;
print &amp;#34;The RaiseError attribute is: &amp;#34; . $dbh-&amp;gt;{RaiseError} . &amp;#34;\n&amp;#34;;
# And you can change values, too...
$dbh-&amp;gt;{AutoCommit} = 1;
print &amp;#34;The AutoCommit attribute is now: &amp;#34; . $dbh-&amp;gt;{AutoCommit} . &amp;#34;\n&amp;#34;;
$dbh-&amp;gt;disconnect();
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The example outputs the following when run:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;Connected!The AutoCommit attribute is: 0
The RaiseError attribute is: 1
The AutoCommit attribute is now: 1
&lt;/code&gt;&lt;/pre&gt;
      </description>
    </item>
    
    <item>
      <title>Connecting-To: Connecting from Perl without a DSN</title>
      <link>/en/connecting-to/client-libraries/accessing/perl/connecting-to-using-perl/connecting-from-perl-without-dsn/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/connecting-to/client-libraries/accessing/perl/connecting-to-using-perl/connecting-from-perl-without-dsn/</guid>
      <description>
        
        
        &lt;p&gt;If you do not want to set up a Data Source Name (DSN) for your database, you can supply all of the information Perl&#39;s DBD::ODBC driver requires to connect to your OpenText™ Analytics Database in the data source string. This source string must the &lt;code&gt;DRIVER=&lt;/code&gt; parameter that tells DBD::ODBC which driver library to use in order to connect. The value for this parameter is the name assigned to the driver by the client system&#39;s driver manager:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;On Windows, the name assigned to the database ODBC driver by the driver manager is Vertica.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;On Linux and other UNIX-like operating systems, the database ODBC driver&#39;s name is assigned in the system&#39;s &lt;code&gt;odbcinst.ini&lt;/code&gt; file. For example, if your &lt;code&gt;/etc/odbcinst.ini&lt;/code&gt; contains the following:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;[Vertica]
Description = Vertica ODBC Driver
Driver = /opt/vertica/lib64/libverticaodbc.so
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;you would use the name Vertica. See &lt;a href=&#34;../../../../../../en/connecting-to/client-libraries/client-drivers/install-config/odbc/creating-an-odbc-data-source-name-dsn/creating-an-odbc-dsn-linux/#&#34;&gt;Creating an ODBC DSN for Linux&lt;/a&gt; for more information about the &lt;code&gt;odbcinst.ini&lt;/code&gt; file.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;You can take advantage of Perl&#39;s variable expansion within strings to use variables for most of the connection properties as the following example demonstrates.&lt;/p&gt;
&lt;p&gt;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;#!/usr/bin/perl
use strict;
use DBI;
my $server=&amp;#39;VerticaHost&amp;#39;;
my $port = &amp;#39;5433&amp;#39;;
my $database = &amp;#39;VMart&amp;#39;;
my $user = &amp;#39;ExampleUser&amp;#39;;
my $password = &amp;#39;password123&amp;#39;;
# Connect without a DSN by supplying all of the information for the connection.
# The DRIVER value on UNIX platforms depends on the entry in the odbcinst.ini
# file.
my $dbh = DBI-&amp;gt;connect(&amp;#34;dbi:ODBC:DRIVER={Vertica};Server=$server;&amp;#34; .
        &amp;#34;Port=$port;Database=$database;UID=$user;PWD=$password&amp;#34;)
        or die &amp;#34;Could not connect to database: &amp;#34; . DBI::errstr;
print &amp;#34;Connected!\n&amp;#34;;
$dbh-&amp;gt;disconnect();
&lt;/code&gt;&lt;/pre&gt;

&lt;div class=&#34;alert admonition note&#34; role=&#34;alert&#34;&gt;
&lt;h4 class=&#34;admonition-head&#34;&gt;Note&lt;/h4&gt;

Surrounding the driver name with braces ({ and }) in the source string is optional.

&lt;/div&gt;&lt;/p&gt;

      </description>
    </item>
    
  </channel>
</rss>
