I'm trying to connect to a database using a PDO Connection via Zend:
<?php
class Feuerwehr_Db extends Zend_Db {
public static function factoryEinsaetze(){
$config = array(
'LOCAL' => array(
'servername' => "localhost",
'username' => "root",
'password' => "admin",
'dbname' => "einsaetze"
),
'LIVE' => array(
'servername' => "rdbms.strato.de",
'username' => "U2340080",
'password' => "*****",
'dbname' => "DB2340080"
)
);
return parent::factory('Pdo_Mysql', $config[Feuerwehr_Environment::getStage()]);
}
}
The Connection selects all login data correctly and creates a DB connection. Everything works fine locally but on my Strato Server the Connection fails with the following exception:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)' in /mnt/web024/d1/57/5707957/htdocs/Beta/library/Zend/Db/Adapter/Pdo/Abstract.php:129 Stack trace: #0 /mnt/web024/d1/57/5707957/htdocs/Beta/library/Zend/Db/Adapter/Pdo/Abstract.php(129): PDO->__construct('mysql:servernam...', 'U2340080', '*****', Array) #1.....
The PHP Version on the server is 5.6 and a standard mysql_connect works perfectly.
Zend expected the key "host" and not "servername". Default param is set as localhost which explains the error exception.
Related
I have PHP-Solr extension version 1.0.3-alpha installed on my server. I'm initializing the connection using:
$options = array(
'hostname' => 'hostname',
'login' => '',
'password' => '',
'port' => '',
'path' => 'solr/core1');
$client = new SolrClient($options);
It returns the following object:
class SolrClient#17 (1) { private $_hashtable_index => int(13444) }
But whenever I try to run a query like:
$qryArray = 'key_id:123456';
$client->deleteByQuery($qryArray);
It throws an exception as follows:
Solr HTTP Error 7: 'Couldn't connect to server
Can anyone help me to find what would causing this issue?
I have tried var_dump($client->getDebug());, but it returns NULL.
I have a project done with Silex, and I was using herrera-io/silex-pdo as the PDO provider, but I faced random crashes with socket errors (I connect to the DB via socket), since that lib is abandoned, I changed to csanquer/pdo-service-provider, and it works just fine on my localhost server, but when I deploy to remote, I get the following error:
PHP Fatal error: Class 'Csanquer\Silex\PdoServiceProvider\Provider\PdoServiceProvider' not found in /app/web/index.php on line 52
Here is the code around the line 52:
use Csanquer\Silex\PdoServiceProvider\Provider\PdoServiceProvider;
$app->register(
// you can customize services and options prefix with the provider first argument (default = 'pdo')
new PdoServiceProvider('pdo'), // Line 52
array(
'pdo.server' => array(
// PDO driver to use among : mysql, pgsql , oracle, mssql, sqlite, dblib
'driver' => 'mysql',
'host' => 'unix_socket=/app/mysqld.sock',
'dbname' => 'db_beta',
'port' => 3306,
'user' => 'user',
'password' => 'pass',
),
// optional PDO attributes used in PDO constructor 4th argument driver_options
// some PDO attributes can be used only as PDO driver_options
// see http://www.php.net/manual/fr/pdo.construct.php
'pdo.options' => array(
\PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'UTF8'"
),
// optional PDO attributes set with PDO::setAttribute
// see http://www.php.net/manual/fr/pdo.setattribute.php
'pdo.attributes' => array(
\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
),
)
);
Thanks in advance for any help, or any clue of what may be going wrong!
Turns out the problem was with the use instructions. To fix, simply change:
use Csanquer\Silex\PdoServiceProvider\Provider\PdoServiceProvider;
To:
use Csanquer\Silex\PdoServiceProvider\Provider\PDOServiceProvider;
And:
new PdoServiceProvider('pdo') To: new PDOServiceProvider('pdo')
Now it works!
Im creating a Zend APIgility application REST service and having a problem with my fetchAll Mapper function.
I'm connecting to an IBM DB2 database running on an i Series server (AS/400) via DB2 Connect on a Windows Application Server.
My Connection is is made in my local.php as such:
return array(
'db' => array(
'driver' => 'IbmDb2',
'database' => $database,
'username' => $user,
'password' => $password,
'hostname' => $host,
'port' => $port,
'driver_options' => array(
'i5_naming' => DB2_I5_NAMING_ON,
'i5_lib' => 'LIBWEB',
),
),
);
The fetchAll() function in my Mapper class is:
public function fetchAll()
{
$select = new Select('WBRESOURCE');
$paginatorAdapter = new DbSelect($select, $this->adapter);
$collection = new ResourcesCollection($paginatorAdapter);
return $collection;
}
When I hit the DbSelect, ZF2 throws the following DB2 Connect error:
"[IBM][CLI Driver][AS] SQL0204N \"*LIBL.WBRESOURCE\" is an undefined name. SQLSTATE=42704"
Im not sure why its using *LIBL (user defined library list), since I defined the library (SCHEMA) to use as LIBWEB in my connection option.
Thanks in advance!
Rob
Try changing this section:
'driver_options' => array(
'i5_naming' => DB2_I5_NAMING_ON,
'i5_lib' => 'LIBWEB',
Change to":
'driver_options' => array(
'i5_naming' => DB2_I5_NAMING_OFF, <=== change
'i5_lib' => 'LIBWEB',
By using DB2_I5_NAMING_OFF, you should get SQL naming mode. The use of DB2 i5 naming mode will result in things like reliance on a job's library list.
See PHP: db2-connect for some info on the parameter.
$mailboxes =
array(
'label' => 'Mail',
'mailbox' => '{mail.example.com:143/novalidate-cert}INBOX',
'username' => "myadress#mail.com",
'password' => "mypassword"
);
imap_open($mailboxes['mailbox'], $mailboxes['username'], $mailboxes['password'])
I have caught this error when I use imap_last_error() :
"Connection failed to mail.example.com,143: Connection timed out"
But when I have tried it in localhost (Wampserveur), everything works fine.
Note: extension=php_imap.dll is enable on my serveur.
Upgraded a (dev) Cake PHP site and had to change database drivers from ADO to SQL Server's own driver as ADO is no longer supported in Cake 1.3, I . The new SQL Server driver is installed in PHP, shows in PHPinfo() and should work, but when I try to load a page using the database, I get this error:
Warning (2): sqlsrv_query() expects parameter 1 to be resource, boolean given
[APP\plugins\datasources\models\datasources\dbo\dbo_sqlsrv.php, line 184]
Warning (512): SQL Error: An invalid parameter was passed to sqlsrv_query.
[CORE\cake\libs\model\datasources\dbo_source.php, line 684]
Query: SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
What appears to be happening is my connection isn't established in the dbo_sqlsrv.php driver; a "$this->connection" variable is supposed to be the connection resource then passed to sqlsrv_query() and it's apparently a bool which is wrong (I tried to Echo the variable and it displays nothing).
This is where the connection SHOULD be set:
sqlsrv_connect($this->config['host'] . $port, $params)
Printing the variables that were passed in gives me this:
SRV, 1433 Array ( [Database] => DB [CharacterSet] => char
[MultipleActiveResultSets] => [UID] => sa [PWD] => password )
Each of those parameters is correct, is there a specific way I should format or change my database configuration array for this driver or is there something I am missing?
This error was due to outdated SQL Server drivers. Installing the latest from below allows a SQL Server connection:
http://www.microsoft.com/download/en/details.aspx?id=20098
I think there is some issue with your connection. PHP can't establish connection with sql Server.
var $default = array(
'driver' => 'sqlsrv',
'persistent' => false,
'host' => 'Myhome-PC\SQLEXPRESS', // or ip-address(192.168.1.13)
'login' => 'username',
'password' => 'password',
'database' => 'db',
'prefix' => 'tbl',
'port' => NULL,
'returnDatesAsStrings' => True
);
I think the Connection should be this
Here is the sqlsrv_dbo which I used.
And your $param should be something like this
$connectionInfo = array("UID" => $config['login'],
"PWD" => $config['password'],
"Database" => $config['database'],
'MultipleActiveResultSets' => 1,
'ConnectionPooling' => 0
);
if(isset($config['ReturnDatesAsStrings'])){
$connectionInfo['ReturnDatesAsStrings'] = $config['ReturnDatesAsStrings'];
}
$this->connection = sqlsrv_connect($config['host'] . $port, $connectionInfo);