I'm trying to build a script that imports items from a production database to a local one, but am having problems switching the connection form production to local.
Doctrine_Manager::getInstance()->setCurrentConnection('prod-slave');
// execute query to get data from production, confirm it worked
Doctrine_Manager::getInstance()->setCurrentConnection('local');
// insert data into local database
When I run this I'm getting this error:
PHP Fatal error: Uncaught exception 'Doctrine_Connection_Mysql_Exception' with message 'SQLSTATE[HY000]:
General error: 1290 The MySQL server is running with the --read-only
option so it cannot execute this statement' in...
If I close the connection to prod-slave before setting it to local I get:
PHP Fatal error: Uncaught exception 'Doctrine_Manager_Exception' with message 'Unknown connection: prod-slave' in...
Notice that in both of these cases, it's still trying to connect to the slave even though I changed the connection to local (In the first case, it must be the slave since it is read-only).
I have also tried manually setting the connections with:
Doctrine_Manager::connection('mysql://path');
Doctrine version: 1.2.3
Symfony version: 1.3.9
Any help would be much appreciated.
Thank you
If you check generated base classes for your models, at the very beginning you will see each of your model is bound to specific connection. So even if you set current connection to another one, the one bound is used.
Solution is to call Doctrine_Manager::getInstance()->bindComponent($component, 'local'); for each of your models.
Instead of using setCurrentConnection try using getConnection
$slave = Doctrine_Manager::getInstance()->getConnection('prod-slave');
$result1 = $slave->execute($some_sql);
$local = Doctrine_Manager::getInstance()->getConnection('local');
$result2 = $local->execute($some_other_sql);
works for me on a symfony 1.4 project.
This should work providing that, in your config/databases.yml, you have the two connections prod-slave and local properly setup. And in your schema files you have bound your tables to the appropriate connections. (Just in case a doc on connections and all that can be found here )
Related
I have a Symfony 3.4 application connected to an Oracle DB via a Wallet, so the configuration of the DB username and password are outside the app and of my control.
To let the application to work with this specific configuration I added in the config.yml, the parameter:
doctrine:
dbal:
connections:
default:
...
session_mode: !php/const OCI_CRED_EXT
...
The application works without any problem.
I have a sync function that connect to different DBs and sync some data.
The sync function can be run manually within the application UI and it works.
I wrote a console command to run in a cron job that instantiate the same set of classes used manually by the application but I got the error in object when I execute the command via terminal.
The exact error is:
In AbstractOracleDriver.php line 57:
An exception occurred in driver: ORA-12154: TNS:could not resolve the connect identifier specified
In OCI8Exception.php line 16:
ORA-12154: TNS:could not resolve the connect identifier specified
The same error occurs when testing the db connection with the console:
#php .\bin\console doctrine:query:sql "select sysdate,current_date from dual"
So, it seams that the console command in some way ignore that the oracle connection i made through a wallet and looks for servicename parameter which is, obviously, empty resulting in a TNS error.
Do someone have some suggestion on how to fix the issue?
Thanks,
Marco
I'm connecting to Redis Labs to use redis for our application.
Here is my configurations:
$conf=[
'scheme'=>'tcp',
'host'=>'ec2.cloud.redislabs.com',
'port'=>12860,
'database'=>'selector',
'password'=>'redispassword'
];
Then I do this to load the predis library:
require "lib/predis/autoload.php";
After which I do this:
$client = new Predis\Client($conf);
Then I try to run a command:
$client->hset('comments',"comment:1","{json_encoded_data}");
And this is the error I receive:
PHP Fatal error: Uncaught exception 'Predis\Connection\ConnectionException' with message '`SELECT` failed: ERR invalid DB index [tcp://cloud.redislabs.com:12860]' in /redis/lib/predis/src/Connection/AbstractConnection.php:155
I've looked online and people say I should set the database as 0 however If I do that how do I use my selected database?
Not sure what to do here.
The host parameter is for your instance endpoint:
And RedisLabs only allows one database per instance, so you'll have no problem using 0 in the database parameter:
That is exactly the reason why each of our Redis Cloud instances
allows using just one database (the default, 0-numbered database).
This ensures that any two databases in our service will never compete
on the resources of a single thread. In fact, trying to use any
database other than 0 with our service should produce an error.
Source
Currently we are running Zend Framework 2 and SQL server for our internal application. We have a stored procedure in place for our AuditTrail. This AuditTrail include a AuditUser who made the change/insert. At this moment this "AuditUser" is username of PDO connection.
We are working towards a situation to change this AuditUser is the active user who made the change and would like to use EXECUTE as USER='[REALUSER]'. And their strange behaviour starts. When executing this statement, everything is doing fine. But when I refresh the page, SQL server returns following errors:
Fatal error: Uncaught exception 'PDOException' with message
'SQLSTATE[HY000]: [Microsoft][SQL Server Native Client
11.0]Unspecified error occurred on SQL Server. Connection may have been terminated by the server.'
Zend\Db\Adapter\Exception\InvalidQueryException: Statement could not
be executed (08S01233 - [Microsoft][SQL Server Native Client
11.0]Shared Memory Provider: No process is on the other end of the pipe.
And after refreshing again, it's executing fine again.
I think it has something todo with session from SQL/PDO(http://msdn.microsoft.com/en-us/library/ms181362.aspx, says session is switched). But I'm unable to resolve this issue. Could somebody help or suggest a way forward?
Regards,
Pim
For those of you who experienced the same problem - this link helped me:
https://blogs.msdn.microsoft.com/brian_swan/2010/11/17/sql-server-driver-for-php-connection-options-connection-pooling/
If you are using sqlsrv function, as I am, the only thing you need to do is setting ConnectionPooling to false, as described in given link:
e.g.
$options = array("Database"=>"master", "UID"=>"user", "PWD"=>"password", "ConnectionPooling"=>0);
I have a very simple SQLite database that I need to read/write to from a different server.
Say the database is stored here : http://www.abc.com/data/data.sqlite
And I'm using PHP to access it from http://www.xyz.com
So my first attempt was the following:
$dbpath = "http://www.abc.com/data/data.sqlite";
$dbconn = "sqlite:$dbpath";
$db = new PDO($dbconn)
No good, I get the following:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [14] unable to open database file'.........PDO->__construct('sqlite:http://w...') #1 {main} thrown
If try and copy the database onto the same server I'm accessing from:
$dbpath = "http://www.xyz.com/data/data.sqlite";
$dbconn = "sqlite:$dbpath";
$db = new PDO($dbconn)
I get the same message.
It's only when I give it a relative path on the same server:
$dbpath = "../data/data.sqlite";
That it actually works.
I know the database URLs and database itself are correct.
So is there a limitation to accessing cross-servers? Anyone know out to solve this issue?
Thanks a lot.
There are no such thing like 'SQLite server'. It exists only in a form of a file.
But there are no files in the HTTP protocol, but URIs only.
So, this is essential incompatibility.
To be able to do remote calls you have 3 choices
Only as a joke: download the file locally before each SELECT query and upload it back after updates
Establish some proxy script, to recieve a query and to return json.
Get yourself a real database server.
Or just change the project architecture to eliminate the need of remote access.
I've got mongodb running in following configuration: 1 config server, 2 mongos, 8 shards (4 per mongos). I've got a problem using rockmongo administration tool:
if I connect to mongos router and try to list databases, I receive the following error:
Fatal error: Uncaught exception 'MongoCursorException' with message 'no primary!' in /home/vissi/var/www/rockmongo/app/models/MDb.php:5 ...
This problem exists only in one mongos, connecting to other mongos gives correct listing. Running db.serverStatus() in mongo console shows ... ok => 1 in both mongos.
if I connect to mongod running with shardsvr option, I see only config and local databases.
How should I connect to see all my databases correctly? phpmoadmin (and mongo console) runs show dbs ok.
If you have more than 1500 reputation, please, add rockmongo tag to this question.
The problem was resolved updating mongos at one of the machines from 1.6.5 to 1.7.3.