Dokku deployed Silex can't find PdoServiceProvider - php

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!

Related

Can't connect to RabbitMQ on Amazon MQ

I created an Amazon MQ broker:
Select broker engine: RabbitMQ 3.8.6
Single-instance broker
Network and security: Public access
VPC and subnets: Use the default VPC and subnet(s)
I have tried two libraries: from RabbitMQ manual and Enqueue\AmqpExt
Either of them cannot connect to Amazon (with docker container all works fine. But I want to try AMAZON MQ.
I used code below:
use Enqueue\AmqpExt\AmqpConnectionFactory;
use PhpAmqpLib\Connection\AMQPSSLConnection;
$connectionFactory = new AmqpConnectionFactory([
'host' => 'b-da219bXXXXXXXXXXXX86a.mq.us-east-1.amazonaws.com',
'port' => 5671,
'vhost' => '/',
'user' => 'xxxx',
'pass' => 'xxxx', // I can login with this to rabbit admin panel
'persisted' => false,
'ssl_on' => false,
'ssl_verify' => false,
]);
$c = $connectionFactory->createContext();
$queue = $c->createQueue('emails');
$c->declareQueue($queue);
Result:
Library error: connection closed unexpectedly - Potential login failure.
With 'ssl_on' => true the same error.
I don't know can it be happen because I didn't provide ssl cert to amazon.
If so, how to fix it?
I've had success with php-amqplib, and I am actually not using the newest version (I am on v2.12.3). I can connect using this:
$connection = new AMQPSSLConnection($host, $port, $user, $pass, $vhost, ['verify_peer_name' => false], [], 'ssl');
I found that I had to set 'verify_peer_name' => false, or else I just got a unable to connect to ssl://localhost:5671 (Unknown error) error, but I was also port-forwarding through localhost.
Amazon MQ broker (RabbitMQ specifically) is using SSL by default (you can notice that connection string starts with amqps, not amqp
In your case, you should set to true ssl_on and ssl_verify options
Answered by #Eugene K in a sub-comment:
You need to add the DSN to the SSLOptions array, and you need to use a AMQPSSLConnection instead of an AMQPStreamConnection
$this->connection = new AMQPSSLConnection(
'myhost.mq.eu-west-1.amazonaws.com',
'5671',
'username',
'xxx',
'/',
[
'dsn' => 'amqps:'
]
);
I see you installed amqp-ext and using it's ConnectionFactory
use Enqueue\AmqpExt\AmqpConnectionFactory; but
If you are using php-enqueue and want to connect to AWS AMQ RabbitMQ you should install and use enqueue/amqp-lib instead of enqueue/amqp-ext
and connection details
use Enqueue\AmqpLib\AmqpConnectionFactory;
new AmqpConnectionFactory([
'host' => env('RABBITMQ_HOST'),
'port' => env('RABBITMQ_PORT', 5672),
'vhost' => env('RABBITMQ_DEFAULT_VHOST'),
'user' => env('RABBITMQ_USERNAME'),
'pass' => env('RABBITMQ_PASSWORD'),
'persisted' => false,
'ssl_on' => true,
'ssl_verify' => true,
]);

ZF2 Zend\Paginator\Adapter\DbSelect on DB2 i Series

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.

jobberBase php installation is not working

I installed jobberBase using automatic installation (softaculous) on arvixe. As this was all automatic installation chances of any errors are rare. Still I did double checked that database got created fine; also the configuration looked fined.
I saw this errors on many other threads too but couldnt find a solution anywhere ; so looks like its a common installation problem. Most probably the php are not able to connect to DB ! Any help would be highly appreciated.
Warning: mysqli::mysqli() expects parameter 5 to be long, string given in /home/muskete3/public_html/jobber/_includes/class.Db.php on line 20
Warning: mysqli::query() [mysqli.query]: Couldn't fetch Db in /home/muskete3/public_html/jobber/_includes/class.Db.php on line 72
Warning: mysqli_error() [function.mysqli-error]: Couldn't fetch Db in /home/muskete3/public_html/jobber/_includes/class.Db.php on line 73
Warning: mysqli::query() [mysqli.query]: Couldn't fetch Db in /home/muskete3/public_html/jobber/_includes/class.Db.php on line 31
Warning: mysqli_error() [function.mysqli-error]: Couldn't fetch Db in /home/muskete3/public_html/jobber/_includes/class.Db.php on line 32
Fatal error: Call to a member function fetch_assoc() on a non-object in /home/muskete3/public_html/jobber/_includes/class.JobberSettings.php on line 23
My configuration file is :
<?php
/**
* Define environments
*
*/
// local (http://localhost/jobberbase/public)
$__instances['local'] = array(
// should be a unique part of the url (or the entire url if you wish)
'prefix' => 'www.jobs41.net',
// mysql credentials
'db_host' => 'localhost',
'db_port' => 3306,
'db_user' => '***',
'db_password' => '***',
'db_name' => '***',
'db_prefix' => '',
// your site's full url
'app_url' => 'http://www.jobs41.net/jobber/',
// error reporting
'ini_error_reporting' => E_ALL,
'ini_display_errors' => 'On',
// environment setting 1 (use 'local' for localhost/testing OR 'online' for live, production environment)
'location' => 'local',
// environment setting 2 (use 'dev' together with 'local' in the previous setting OR 'prod' with 'online')
'environment' => 'dev',
//'apache_mod_rewrite', 'iis_url_rewrite' -microsoft URL Rewrite module, 'iis_isapi_rewrite'
'rewrite_mode' => 'apache_mod_rewrite'
);
// live (http://www.yourjobberbasedomain.com)
$__instances['live'] = array(
'prefix' => 'www.jobs41.net',
'db_host' => 'localhost',
'db_port' => 3306,
'db_user' => 'muskete3_jobb563',
'db_password' => '6Sn82hxv7P',
'db_name' => 'muskete3_jobb563',
'db_prefix' => '',
'app_url' => 'http://www.jobs41.net/jobber/',
'ini_error_reporting' => E_ALL,
'ini_display_errors' => 'Off',
'location' => 'online',
'environment' => 'prod',
'rewrite_mode' => 'apache_mod_rewrite'
);
Previously I had installed it not as root directory; hence it was installed inside public_html/job.. Now when i installed it again in root directory it worked fine.

Making CakePHP work with SQL server 2008

I can call SQL server 2008 from PHP with Microsoft Drivers for PHP for SQL Server But as Sqlsvr driver class is needed to use CakePHP with SQL server 2008, I got the driver file from following repository.
However, when running my test cakephp with following database.php
<?php
class DATABASE_CONFIG {
var $default = array(
'driver' => 'sqlsvr',
'host' => 'localhost\EPHP',
'login' => 'sa',
'password' => 'xxxxxxx',
'database' => 'Blog',
);
}
?>
I got following error:
Fatal Error (256): ConnectionManager::loadDataSource - Unable to import DataSource class .DboSqlsvr [CORE\cake\libs\model\connection_manager.php, line 185]
Then I have read all the you-cannot-make-cakePHP-work-with-sql-2008 discussions. Is there any resolution by now?
UPDATE: Let me rephrase my question. I would appreciate if someone successfully made CakePHP work with SQL 2008 and tell me the procedure he followed to do that.
After some research, I found this article ( http://book.cakephp.org/view/1652/Plugin-DataSources-and-Datasource-Drivers). Basically, you can not place your driver file in the directory ( \cakephp\cake\libs\model\datasources\dbo) where the "factory" driver files are located. Instead you should place the driver file in following directory of your baked cake.
your-cake-application\plugins\your-plugin-name\models\datasources\dbo
And then you should change your database.php in config accordingly.
<?php
class DATABASE_CONFIG {
var $default = array(
'driver' => 'your-plugin-name.DboSqlsrv',
'host' => 'localhost\EPHP',
'login' => 'sa',
'password' => 'xxxxxxx',
'database' => 'Blog',
);
}
?>
After this, I could run my cakephp app.
Assuming you have the datasources in the folder app/model/datasource/dbo_sqlsrv.php load it like this:
<?php
class DATABASE_CONFIG {
var $default = array(
'datasource' => 'sqlsvr',
'host' => 'localhost\EPHP',
'login' => 'sa',
'password' => 'xxxxxxx',
'database' => 'Blog',
);
}
?>
The difference is in the 'driver' vs 'datasource' keyword

Error using Cake PHP SQL Server Driver

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

Categories