I'm trying to install PAMI library
I installed it via pear:
# pear channel-discover pear.marcelog.name
# pear install marcelog/PAMI
and trying to use example.php
$pamiClientOptions = array(
'host' => '127.0.0.1',
'scheme' => 'tcp://',
'port' => 9999,
'username' => 'admin',
'secret' => 'mysecret',
'connect_timeout' => 10000,
'read_timeout' => 10000
);
use PAMI\Client\Impl\ClientImpl as PamiClient;
$pamiClient = new PamiClient($pamiClientOptions);
// Open the connection
$pamiClient->open();
// Close the connection
$pamiClient->close();
when I try to use this script I receive error:
Class 'PAMI\Client\Impl\ClientImpl' not found
It's first time, I see that classes are included like this (use).
I'm using debian Linux also. Please, help.
UPDATE
Also it's installed in /usr/share/php/PAMI/
Solved. I've found solution in "in_depth explanation"
You had to do this after pear installation
require_once '/usr/share/php/PAMI/Autoloader/Autoloader.php';
PAMI\Autoloader\Autoloader::register();
I put this two strings at top of my script and it works now. But it also receives strange
PHP Fatal error: Class 'Logger' not found in
I solve this by installing log4php:
$ pear channel-discover pear.apache.org/log4php
$ pear install pear.apache.org/log4php/Apache_log4php-2.1.0
And also you should put before first require_once -
require_once '/usr/share/php/log4php/Logger.php';
Related
UPDATE: This question has been flagged as a question that has been solved already. But when checked, those previous "similar" questions require users to download the corresponding .dll file which is not applicable for macOS users and other answers did not explicitly elaborate on how to install needed extensions like pdo_sqlsrv, sqlsrv, and ODBC for XAMPP-installed PHP.
I'm trying to connect to MS SQL database using CodeIgniter 3.1.9 via ODBC:
$db['default'] = array(
'dsn' => '',
'hostname' => 'x.x.x.x',
'username' => 'sa',
'password' => 'xxx',
'database' => 'xxx',
'dbdriver' => 'odbc'
But I'm getting this error:
An uncaught Exception was encountered
Type: Error
Message: Call to undefined function odbc_connect()
Filename: /Applications/XAMPP/xamppfiles/htdocs/gpweb/system/database/drivers/odbc/odbc_driver.php
Line Number: 141
PHP is installed via XAMPP. I checked the php.ini file to get information about ODBC and the line below is disabled because of the semi-colon in the beginning:
;extension=php_pdo_odbc.dll
I know it is irrelevant because I'm running on MacOS and .dll files are for Windows (but I still tried enabling it and with more errors):
A PHP Error was encountered
Severity: Core Warning
Message: PHP Startup: Unable to load dynamic library '/Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20160303/php_pdo_odbc.dll' - dlopen(/Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20160303/php_pdo_odbc.dll, 0x0009): tried: '/Applications/XAMPP/xamppfiles/lib/php_pdo_odbc.dll' (no such file), '/Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20160303/php_pdo_odbc.dll' (no such file)
Filename: Unknown
Line Number: 0
Has anyone encountered this issue before and how did you solve it? How can you enable ODBC in MacOS with PHP installed using XAMPP?
I found the solution, missing in php.ini
extension=php_odbc.dll
Unfortunately, macOS users that use XAMPP to install PHP have no way to install extensions like sqlsrv, pdo_sqlsrv, and ODBC, unlike in Windows, where they can download the necessary .dll files and enable extensions in the php.ini.
I've been using CodeIgniter 3.x.x for years to create web applications and MySQL as the database. I wanted to utilize the said PHP library with my other projects requiring MSSQL as the database since CI can do so, provided that you have installed the necessary extensions.
I have scoured the internet and there is really no definite solution to install extensions in XAMPP-installed PHP running macOS.
I gave up and installed PHP using homebrew instead. In your terminal, enter:
$ brew install php
Then installed sqlsrv extension (for M1 ARM64 users)
sudo CXXFLAGS="-I/opt/homebrew/opt/unixodbc/include/" LDFLAGS="-L/opt/homebrew/lib/" pecl install sqlsrv
sudo CXXFLAGS="-I/opt/homebrew/opt/unixodbc/include/" LDFLAGS="-L/opt/homebrew/lib/" pecl install pdo_sqlsrv
Then the ODBC extension:
HOMEBREW_NO_ENV_FILTERING=1 ACCEPT_EULA=Y
brew install msodbcsql17 mssql-tools
Since I cannot use the XAMPP-installed PHP, I have to use the CodeIgniter 4 to use the natively installed PHP:
composer create-project codeigniter4/appstarter project-root
After that, in the /project/app/Config/Database.php of my CodeIgniter 4 project, setup the connection to the database:
public $default = [
'DSN' => '',
'hostname' => 'x.x.x.x', // IP ADDRESS OF THE SQL SERVER
'username' => 'xxx', // USERNAME
'password' => 'xxx', // PASSWORD
'database' => 'xxx', // NAME OF DATABASE
'DBDriver' => 'SQLSRV', // DATABASE DRIVER TO BE USED
'DBPrefix' => '',
'pConnect' => false,
'DBDebug' => (ENVIRONMENT !== 'production'),
'charset' => 'utf8',
'DBCollat' => 'utf8_general_ci',
'swapPre' => '',
'encrypt' => false,
'compress' => false,
'strictOn' => false,
'failover' => [],
'port' => 1433, // DEFAULT PORT FOR SQL SERVER
];
This is not the solution to the original problem (XAMPP-installed PHP), but an alternative solution to connect to MSSQL database using PHP.
REFERENCE:
https://learn.microsoft.com/en-us/sql/connect/php/installation-tutorial-linux-mac?view=sql-server-ver16
https://www.codeigniter.com/user_guide/installation/index.html
But still, if you found a way to install sqlsrv and ODBC extensions in XAMPP-installed PHP running macOS, please don't hesitate to post it here.
I am trying to connect to MongoDB via PHP.
mongod --version
db version v3.2.8
Then,
php -i | grep mongo
/etc/php/7.0/cli/conf.d/20-mongodb.ini,
mongodb
mongodb support => enabled
mongodb version => 1.1.8
mongodb stability => stable
libmongoc version => 1.3.5
mongodb.debug => no value => no value
I tried:
sudo pecl install mongodb
which returns
pecl/mongodb is already installed and is the same as the released version 1.1.8
install failed
which (the install failed bit) gets redressed if I try:
sudo pecl uninstall mongodb
and
sudo pecl install mongodb
I have this php file:
<?php
echo "I am here";
$connection = new Mongo('localhost');
$db = $connection->mydb;
$list = $db->listCollections();
foreach ($list as $collection) {
echo "$collection </br>";
}
echo "I am never here";
?>
I cannot see the second echo.
I would appreciate any thoughts.
Thank you.
First, check #sanjay comment and then apply this connection:
$db = new MongoClient('mongodb://localhost', [
'username' => 'root',
'password' => '',
'db' => 'YOUR DB'
]);
Hope it will work for you.
I managed to have it working. Thanks to this post:
After upgrading PHP to version 7, why can't I use the mongodb driver?
and this post:
Using the PHP Library for MongoDB (PHPLIB)
Sorry as it seems pretty odd (to me!) but indeed: MongoClient() has become (verbatim! with the slash!) MongoDB\Client().
Hence, the file I had in my original post becomes:
<?php
require 'vendor/autoload.php';
echo "I am here";
$manager = new MongoDB\Client();
$database = $manager->mydb;
foreach ($database->listCollections() as $databaseInfo) {
var_dump($databaseInfo);
}
echo "I managed to arrive here";
?>
and I can see the contents of mydb as well as the 2 echos. The vendor/autoload.php was generated by
sudo composer require "mongodb/mongodb=^1.0.0"
as I ran it from within the directory of the php file above. Probably not the best idea as I, now, have to resolve how to make the autoload.php (and all it carries with) globally available. But, nonetheless, at least, I managed to arrive somewhere.
I am using: PHP 7.0.8-0ubuntu0.16.04.2 (cli) ( NTS )
under: Ubuntu 16.04.1 LTS
I have installed composer on my pc and running a pin payment script.
require_once __DIR__.'/vendor/autoload.php';
use Omnipay\Common\GatewayFactory;
$gateway = GatewayFactory::create('Pin');
$gateway->setSecretKey('1111111111');
$gateway->purchase(array(
'email' => 'abc.php2#gmail.com',
'description' => 'Widgets',
'amount' => '49.99',
'currency' => 'USD',
'card_token' => $_REQUEST['card_token'],
'ip_address' => $_REQUEST['ip_address']
))->send();
I am not sure about require_once _DIR_.'/vendor/autoload.php'; , where can i find the exact path for the same.
I think as you as "but where do I find the vendor" that you did not run the composer install command.
You have to run it in order to create the vendor dorectory and download the packages. Find out more in the documentation: http://getcomposer.org/doc/00-intro.md#using-composer
Basically, run:
composer install
I'm using composer to manage dependencies. And basically want I want to do is automatically run composer update in puppet config when vagrant up is running.
I'm using puphpet to generate puppet files for vagrant.
I added composer::exec section in this code in the default.pp file:
if $php_values['composer'] == 1 {
class { 'composer':
target_dir => '/usr/local/bin',
composer_file => 'composer',
download_method => 'curl',
logoutput => true,
tmp_path => '/tmp',
php_package => "${php::params::module_prefix}cli",
curl_package => 'curl',
suhosin_enabled => false,
}
composer::exec { 'composer-update':
cmd => 'update',
cwd => '/var/www/myproject'
}
}
Some times I'm getting this error in output:
Error: Command exceeded timeout
Error: /Stage[main]//Composer::Exec[composer-update]/Exec[composer_update_composer-update]/returns: change from notrun to 0 failed: Command exceeded timeout
And there is no timeout property in puppet composer.
How to solve it?
Take a look at http://docs.puppetlabs.com/references/latest/type.html#exec-attribute-timeout - it is possible to set a timeout for an exec resource. If the puppet composer module does not provide an option to override that, it really should IMO. And if by a chance it is composer itself that's timing out, not puppet exec, you'd wanna try
export COMPOSER_PROCESS_TIMEOUT=600
Having never touched Doctrine before (either 1 or 2), I am following this tutorial for Doctrine 2.
I'm at the point where I use the command line to generate the database schema. This is the cli-config.php file, as per the tutorial:
<?php
$cliConfig = new Doctrine\Common\Cli\Configuration();
$cliConfig->setAttribute('em', $entityManager);
When I run it though, I just get an error:
Fatal error: require(): Failed opening required 'Doctrine\Common\Cli\Configuration.php'
Because that class referenced by the cli-config.php file doesn't exist. I've also tried blanking the cli-config.php file, which of course doesn't work either - says that "The helper "em" is not defined."
I'm using version 2.0.0BETA3. I know that this is a beta version, so they could have changed some files around, but I can't find that class anywhere.
Any ideas on how to get it working?
The docs in the XML Getting Started are outdated in this regard. Please see the Tools section in the manual on how to configure the CLI Tool:
http://docs.doctrine-project.org/projects/doctrine-orm/en/2.0.x/reference/tools.html
All the rest still works as described. I will update this part asap.
Assuming you installed Doctrine using pear
$ sudo pear install pear.doctrine-project.org/doctrineORM
which will install the three 'Doctrine 2' packages: DoctrineCommon, DoctrineDBAL, and DoctrineORM. On Ubuntu, these packages will be located in /usr/share/php/Doctrine, and the doctrine command line utility, will be installed into /usr/bin.
With this setup, this is a version of cli-config.php you can use (note: DIR should have two underscores before and after it. For some reason they didn't display).
<?php
require ‘Doctrine/ORM/Tools/Setup.php’;
// Setup Autoloader (1)
Doctrine\ORM\Tools\Setup::registerAutoloadPEAR();
require_once 'Doctrine/Common/ClassLoader.php';
$classLoader = new Doctrine\Common\ClassLoader('Entities', __DIR__);
$classLoader->register();
$classLoader = new Doctrine\Common\ClassLoader('Proxies', __DIR__);
$classLoader->register();
$config = new \Doctrine\ORM\Configuration();
$config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache);
$driverImpl = $config->newDefaultAnnotationDriver(array(__DIR__."/Entities"));
$config->setMetadataDriverImpl($driverImpl);
$config->setProxyDir(__DIR__ . '/Proxies');
$config->setProxyNamespace('Proxies');
$connectionOptions = array(
'driver' => 'pdo_mysql',
'dbname' => 'bugs',
'user' => 'bugs',
'password' => 'xyzabc',
'host' => 'localhost' );
$em = \Doctrine\ORM\EntityManager::create($connectionOptions, $config);
$helperSet = new \Symfony\Component\Console\Helper\HelperSet(array(
'db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($em->getConnection()),
'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($em)
));