I want the query 'SET NAMES utf8' to execute before any other queries.
But, if I execute it in the beginning of my app, it forces Zend_Db to connect to the Database, even if I'm not running any other queries. It isn't cool: My app processes lots of requests without any queries, only using cache.
How to ask Zend_Db to run 'SET NAMES utf8' right after connection?
Sure, simply pass the 'charset' option in with the adapter params. You can do this via Zend_Config or in code:
$params = array(
'host' => '127.0.0.1',
'username' => 'webuser',
'password' => 'xxxxxxxx',
'dbname' => 'test',
'charset' => 'utf8'
);
$db = Zend_Db::factory('Pdo_Mysql', $params);
Reference: http://framework.zend.com/manual/en/zend.db.html#zend.db.adapter.connecting.parameters
check this link for config option , its more easier
How to make PDO run SET NAMES utf8 each time I connect, In ZendFramework.
Related
I have a script that connects to an SFTP server with the following code:
use Net::SFTP::Foreign;
my %cfg = (
user => "$user",
password => "$password",
port => 22,
more => [-o => 'StrictHostKeyChecking no']
);
my $sftp = Net::SFTP::Foreign->new("$host",%cfg);
I am using StrictHostKeyChecking to make sure the script automatically accepts the ssh key.
The issue begins when the server replaces the host key with new one. I get the error: WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!
So I have to manually remove the key by running ssh-keygen -R testserver.com
After that the script works fine again.
I am trying to find a way to autmatically replace the key if it changes.
Technically I can run ssh-keygen -R testserver.com every time the script runs, but I do not like that solution.
So far I am not able to a good automated way to replace the key.
Add another option that points UserKnownHostsFile to /dev/null should do the trick, not that it's recommend from security perspective ;-)
use Net::SFTP::Foreign;
my %cfg = (
user => "$user",
password => "$password",
port => 22,
more => [-o => 'StrictHostKeyChecking=no',
-o => 'UserKnownHostsFile=/dev/null']
);
my $sftp = Net::SFTP::Foreign->new("$host",%cfg);
I currently use the following code to connect to a database in my Perl script:
my $dsn = 'dbi:ODBC:MYDATABASE';
my $database = 'uat_env';
my $user = 'user';
my $auth = 'password';
my $dbh = DBI->connect($dsn, $user, $auth, {
RaiseError => 1,
AutoCommit => 1
}) or die("Couldn't connect to database");
$dbh->do('use '.$database);
Now the port has changed from 1433 to 40450.
I am having trouble changing the port in the DSN. I thought this change would work but I am receiving a "DSN not found" error:
my $dsn = 'dbi:ODBC:MYDATABASE;Port=40450';
Any idea why this isn't working?
There are two formats for a DBI data source string for ODBC. You can say either
dbi:ODBC:DSN=MYDATABASE
or you can abbreviate that to
dbi:ODBC:MYDATABASE
which is what you have. If you use just the DSN then you can't add any more parameters, so your dbi:ODBC:MYDATABASE;Port=40450 is looking for DSN MYDATABASE;Port=40450 which clearly doesn't exist
The proper way to do this is to set up a new DSN which has a copy of all the parameters of MYDATABASE, but with a different port name
At a guess, I would say you may be able to write
dbi:ODBC:DSN=MYDATABASE;Port=40450
but I can't be sure and I have no way of testing
If your requirements are simple then you can supply all of the parameters instead of a DSN, like this
dbi:ODBC:Driver={SQL Server};Server=11.22.33.44;Port=40450
but you will have to supply the correct driver if you aren't using a SQL Server ODBC connection, and other parameters may be necessary
You should start by examining the values in the MYDATABASE DSN and go from there
I'm new to ZF. I'm using wamp 3. I followed the instructions from the Zend Framework Documentation (https://framework.zend.com/manual/2.4/en/user-guide/database-and-models.html), installed ZendSkeletonApplication and everything worked fine until step 3 (routing and controllers) when I got the error:
"A 404 error occurred
Page not found.
The requested URL could not be matched by routing.
No Exception available".
I don't know what the problem is, since I copied everything from the tutorial on the site (so that I don't make any typo) and it still won't work.
Any suggestions what the problem might be?
module.config.php looks like this:
return array(
'controllers' => array(
'invokables' => array(
'Album\Controller\Album' => 'Album\Controller\AlbumController',
),
),
'router' => array(
'routes' => array(
'album' => array(
'type' => 'segment',
'options' => array(
'route' => '/album[/:action][/:id]',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
),
'defaults' => array(
'controller' => 'Album\Controller\Album',
'action' => 'index',
),
),
),
),
),
'view_manager' => array(
'template_path_stack' => array(
'album' => __DIR__ . '/../view',
),
),
);
I did everything as they wrote, but when I go to "myvirtualhostname/album" it shows me the error above.
make sure you add this line (highlighted by comment) to the top of your public/index.php
<?php
use Zend\Mvc\Application;
use Zend\Stdlib\ArrayUtils; //<-- add this line
Note#1: you need to follow instructions of editing the index.php file for developing mode enabled, they just forgot to tell about using ArrayUtils in this tutorials.
Note#2 make sure to enable dev mod from the composer and dump autoload like this :
$ composer development-enable
and then:
[$ composer dump-autoload]
I believe you can specify the version you want to install with the initial composer command, something like this:
composer create-project -sdev zendframework/skeleton-application:^2.4 path/to/zf2-app
although you may be able to change the version on your existing skeleton app, it might be easier to run the above command in a different folder, and then copy over the files you've added or changed whilst following the tutorial.
And just to say again, unless you specifically need to learn ZF2.4, it would be better to stick with ZF3 (since that's the current version), and just follow the ZF3 tutorial instead. The differences between them are not that big.
Sometimes, I use any of the following mentioned names to name the install/upgrade scripts in custom modules:
install-0.1.0.0.php
upgrade-0.1.0.0-0.1.1.0.php
upgrade-0.1.1.0-0.1.2.0.php
----------------------------
install-0.1.0.php
upgrade-0.1.0.0-0.1.1.php
upgrade-0.1.1-0.1.2.php
Is there a standard way to follow for this naming conventions for install/upgrade scripts?
Versioning follows some conventions/standards, here is the code snippet from Mage.php to give an idea how module versions can be decided. This is for Magento version 1.7.0.2
array(
'major' => '1',
'minor' => '7',
'revision' => '0',
'patch' => '2',
'stability' => '',
'number' => '',
);
As I know, there's no standard way and you can name your scripts and versions as you need( it uses php version_compare anyway).
Here's is what I am doing
my $username = "user";
my $password= "pass";
my $host="xxx.xxx.xxx.xxx";
my $scpe = Net::SCP::Expect->new(user => $username,
password => $password,
preserve => 1,
recursive => 1,
verbose=>1,
auto_yes=>1);
$scpe->scp("$file","$host:./drop/drop.txt");
When I run this code there is no error I am using unix box, $file is in my directory and have full permissions, also I have changed the directory to temp in unix box but when somebody else runs this code they get
Problem performing scp: Are you sure
you want to continue connecting
(yes/no)? at scp.pl line 242
I am very confused why is it happening, as this error is not received by me
Short answer:
Raise the timeout_auto value:
my $scpe = Net::SCP::Expect->new(user => $username,
password => $password,
preserve => 1,
recursive => 1,
verbose=>1,
timeout_auto=>10, #For example - 5 should probably be plenty
auto_yes=>1);
Long answer.
The
problem performing scp
is what Net::SCP::Expect prepends to the literal error message it gets from SCP itself, so in this case
Are you sure you want to continue
connecting (yes/no)?
This usually happens because the host SCP is connecting to is not yet known.
You should set auto_yes to 1 if you want to avoid this error as the CPAN Documentation for NET::SCP::Expect explains, but I see you're already doing that.
If that doesn't help, consider raising the timeout_auto value. It defaults to 1 second, but if it takes longer for SCP to pose the 'are you sure' question (because for example the DNS looking of the host takes longer), it might not be enough.