I'm doing my own website and i'm using a PDO library here. I have somes library working fine but this one for any reason cannot be "detected"
Files in the folder:
Installed lib using composer => /main/assets/
File where i want to use the lib => /main/user/index.php
Lib path => /main/assets/vendor/faapz/pdo/...
Reproduce this:
1: In a folder (main), create another folder named "assets", then execute the command "composer require faapz/pdo" (this require an installation of composer)
2: In the folder (main), create folder named "user" and create new php file.
3: Use this code
<?php
// => Class 'FaaPz\PDO\Database' not found in ...\main\user\file.php on line 10
$parent_dir = dirname(__DIR__);
require $parent_dir . '/assets/vendor/autoload.php';
$db = new \PDO('mysql:dbname=your_db_name;host=your_db_host;charset=utf8mb4', 'root', ''); // Working lib
$query = 'mysql:host=your_db_host;dbname=your_db_name;charset=utf8';
$user = 'root';
$pass = '';
$database = new FaaPz\PDO\Database($query, $user, $pass); // Not working lib => Class 'FaaPz\PDO\Database' not found in ...\main\user\file.php on line 10
$auth = new \Delight\Auth\Auth($db); // Working lib
?>
I found the package "ext-pdo" work for my problem. Just install it using composer with the following command => composer require ext-pdo
Related
I am trying to include a package from composer, but I am receiving a class not found error.
I have tried the below possibilities.
$supermeteor = new \Supermeteor\Supermeteor('XXXXXXXX');
and
use Supermeteor\Supermeteor;
$supermeteor = new Supermeteor('xxxxxxxx');
Packages composer.json:
"psr-4": {
"Supermeteor\\": ""
}
Packages namespace :
namespace Supermeteor;
Packages class name :
class Supermeteor() {}
Error message
Uncaught Error: Class 'Supermeteor\Supermeteor' not found in
C:\path\to\my\file.php:16
I just tested your package locally, and it seems to work fine for me using the same code as you provided in your question. This is how I tested it.
1. Create a new project
Create a new directory on your computer.
2. Add the package to a new project using Composer
Locate your new directory on the command line and add the package to your projects autoloader by running the below composer command.
composer require supermeteor/sdk-php
3. Use the package
Create an index.php file in the same directory as your composer.json and add the below code.
<?php
require_once __DIR__ . '/vendor/autoload.php';
use Supermeteor\Supermeteor;
$supermeteor = new Supermeteor("xxx");
4. Test the results
In the terminal window start a new php server to serve your project.
php -S localhost:8089
Now access the site via your browser at http://localhost:8089.
I'm running my php in cli under my user.
I have installed composer and autoloader.php does exist. Under vendor folders and file have been downloaded (autoload.php aws, bin, composer, guzzlehttp, mtdowling and psr)
Now in my php code I do:
// Include the SDK using the Composer autoloader
require 'vendor/autoload.php';
use Aws\Route53\Route53Client;
use Aws\Common\Credentials\Credentials;
$credentials = new Credentials('KEY', 'SECRETKEY');
$client = Route53Client::factory(array(
'credentials' => $credentials
));
When I run the script I get: PHP Fatal error: Class 'Credentials' not found in /home/user/updatedns.php on line 15
I tried running it a sudo also (in case it needs to write to the directory) and still get this error.
Just found out that use Aws\Common\Credentials\Credentials; is now under use Aws\Credentials\Credentials;
I've installed Doctrine using composer, and when I try to create the database I get the error:
#!/usr/bin/env php
Why am I seeing this error - no database is created. I obtain the same error if I run update --force. I've also tried orm:schema-tool:create, and I've also tried running the doctrine php file directly php ./vendor/bin/doctrine.php orm:schema:create with the same error.
I have an bootstrap file and a cli-config file as such
// bootstrap.php
<?php
require_once 'vendor/autoload.php';
// Create a simple "default" Doctrine ORM configuration for Annotations
$isDevMode = true;
$config = \Doctrine\ORM\Tools\Setup::createAnnotationMetadataConfiguration(array(__DIR__."/"), $isDevMode);
// database configuration parameters
$conn = array(
'driver' => 'pdo_sqlite',
'path' => __DIR__ . '/db.sqlite',
);
// obtaining the entity manager
$entityManager = \Doctrine\ORM\EntityManager::create($conn, $config);
// cli-config.php
<?php
require_once "bootstrap.php";
return \Doctrine\ORM\Tools\Console\ConsoleRunner::createHelperSet($entityManager);
After much debugging, the path in this line is horribly wrong:
$config = \Doctrine\ORM\Tools\Setup::createAnnotationMetadataConfiguration(array(__DIR__."/"), $isDevMode);
Fixing it so it points to where the class files with mapping data is stored fixed it.
Installed PHPUnit via PEAR and copied the latest repository from https://github.com/sebastianbergmann/phpunit/
Wrote a basic test and saved it in the root directory (also tried /Tests/)
<?php
require_once 'PHPUnit/Autoload.php';
class CalculatorTest extends PHPUnit_Framework_TestCase{
public function testAdd(){
$c = New Calculator();
$result = $c->add(5, 10);
$this->assertEquals(15, $result);
}
}
Throws errors about not being able to load require_once(SebastianBergmann/Diff/autoload.php) In the PHPUnit/Autoload.php there is three lines, 69, 70 and 71.
require_once 'SebastianBergmann/Diff/autoload.php';
require_once 'SebastianBergmann/Exporter/autoload.php';
require_once 'SebastianBergmann/Version/autoload.php';
The directory SebastianBergmann doesn't even exist.... why are these lines in here?
What am I doing wrong, did I copy from the wrong place?
Also trying to run /Tests/Runner/BaseTestRunnerTest.php fails with Class 'PHPUnit_Runner_BaseTestRunner' not found
You cannot just clone it and expect to work. Either completely install via PEAR or composer.
As of those particular references - they are satisfied as composer dependencies: see here https://github.com/sebastianbergmann/phpunit/blob/master/composer.json#L32
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)
));