ZF2 and SQL server 'execute as user' - php

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);

Related

PDO returns "SQLSTATE [HY000]: General Error: 10 Disk I/O error" on sqlite database load

A bit about my current setup, The website is hosted on a windows server 2012 IIS with PHP 7.1, the site runs using Laravel with Medoo to load the database, however on any form of SQL statement the code fails with the error mentioned in the title.
Currently the file permissions are on Full Control for debug purposes
The code used for the call is the following
$pdo = new \Medoo\Medoo([
'database_type' => 'sqlite',
'database_file' => $config->database_path
]);
$query = $pdo->select('computers', '*');
I have tried making a SQL dump of the SQLite database file using a program called "DB Browser for SQLite" and the making a new database file from scatch then importing the SQL dump.
When this is done the program works without problem, so my current thought is there might be a limit on PDO SQLite file limit size since the original file is about 2.8MB while the new is 1.9MB
Is there anyone who have encounter a similar problem? or have any advice on how to fix the current problem?

Issue connecting to PHP with Ajax chat

Using Ajax integrated chat with PHPBB3. It is supposed to use the mysql connections that the site uses. The database tables have been created. When accessing, I continue to get the error
'>[phpBB Debug] PHP Warning: in file [ROOT]/phpbb/di/container_builder.php on line 291: file_put_contents([ROOT]/chat/../cache/container_[ROOT]/chatslashdotdotslash.php): failed to open stream: Invalid argument Error-Report: No connection could be made because the target machine actively refused it. Error-Code: 2002'
Edit: I have not had any trouble connecting to the database with the web application itself. I've read that the hosts file may need to be edited. I made sure that the socket server option for AJAX chat is set to false. I'm not sure what this error is actually trying to say here or what the actual connection error is. Can someone point me in the right direction?
The php class container_builder is where the error falls. Here is the function being called at that point:
protected function dump_container($container_filename)
{
$dumper = new PhpDumper($this->container);
$cached_container_dump = $dumper->dump(array(
'class' => 'phpbb_cache_container',
'base_class' => 'Symfony\\Component\\DependencyInjection\\ContainerBuilder',
));
file_put_contents($container_filename, $cached_container_dump);
I cleared out the particular cache file, which was then recreated, but the error does not go away. I would think there is no problem with connectivity to the database by the application. Cache is stored on the server not the database.

Can't change doctrine connection

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 )

Cannot connect to MySQL Database with MDB2 (Error not Found)

In first point. I am absolutely a noob in PHP and PEAR. For exercising I have worked with PHP, Pear and Mondial DB of Oracle offline, but now I wanted to connect to my Database on 1and1.com.
Following I have tried:
$dsn = 'mysql://dbo5235xxxxx#10.24.xxx/db5235xxxxx'; //Have it tried with password too and many other variations
$sql = "SELECT * FROM Vereine";
$db = MDB2_Util::connect($dsn);
If I upload this file on my webserver and when I try to call this page, I get an error.
Fehler beim Verbindungsaufbau mit [mysql://dbo5235xxxxx#10.24.xxx/db5235xxxxx] : MDB2 Error: not found
The error Message:
"Fehler beim Verbindungsaubau" is an own deinied Message in MDB2_Util.
If I try to connect with MDB2::connect, then the Message calls only:
MDB2 Error: not found
What can be the Error? Why it doesnt show the real Error or a helpful hint. Can I debug? If yes, how?
Best Regards Benny
This can occur even if you have installed an MDB2 driver, but PHP can't find or can't read it.
As a practical example, I experienced this problem on a system on which the UMASK value had been changed from 022 to 027. Even though the MDB2 driver had been installed (with root privileges), the user under whom php-fpm was running lacked access to the library's files.

Using PHP/oci8 to Connect to Oracle Remote DB - Unsure how to use listener

Overall goal of my project is to connect to a Oracle database that is on another server, to query it using PHP, so that I can create charts of the data using JavaScript.
My server is running CentOS
So far I have followed the directions out on the web and have installed oci8 on my server as well as Oracle Insant Client.
I then created a shell script to tunnel to the remote server.
Next I created a test php file to try and connect to the database
<?php
$conn = oci_connect('name', 'pw', 'servername/databasename');
if(!$conn){
$e = oci_error();
trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}
oci_close($conn);
?>
When I load this in the browser I am getting the following error
Warning: oci_connect(): ORA-12541: TNS:no listener in /var/www/html/djc/ociConnect.php on line 3 Fatal error: ORA-12541: TNS:no listener in /var/www/html/djc/ociConnect.php on line 6
I have done my research about the error, and I know the major problem is
lsnrctl start
does not work, I have no lsnrctl function. I also do not have a TNSNAMES.ORA, or LISTENER.ORA file.
I do not know how to get lsnrctl to work on my server, or if I am even attacking this problem from the correct angle.
Also trying to start sqlplus(which I installed from rpm), returns command not found.
Any suggestions?
I am not even sure if I am going about achieving my goal in the correct manor, so any help is greatly appreciated.
I used to connect with:
//Putenv("NLS_LANG=SPANISH_SPAIN.WE8ISO8859P15");
$db="(DESCRIPTION=
(ADDRESS_LIST=
(ADDRESS=(PROTOCOL=TCP)
(HOST=$GLOBALS[dbhost])(PORT=$GLOBALS[dbport])
)
)
(CONNECT_DATA=(SID=$GLOBALS[dbname]))
)";
$conn = OCILogon($GLOBALS['dbuser'],$GLOBALS['dbpasswd'],$db);
Replace $GLOBALS['dbuser'], $GLOBALS['dbpasswd'], $GLOBALS[dbhost], $GLOBALS[dbname], $GLOBALS[dbport] accordingly.

Categories