Web lists-archives.com

[PHP] Error with composer




I am using PDO + composer and I have an error with some .php and with others not that I have not been able to solve

Fatal error: Uncaught Error: Class 'PostgreSQL\PostgreSQLPHPInsert' not found in /var/www/postgresqlphpconnect/indexinsert.php:11 Stack trace: #0 {main} thrown in /var/www/postgresqlphpconnect/indexinsert.php on line 11

Next I show my .php:

<?php
require 'vendor/autoload.php';

use PostgreSQL\Connection as Connection;
use PostgreSQL\PostgreSQLPHPInsert as PostgreSQLPHPInsert;

try {
    // connect to the PostgreSQL database
    $pdo = Connection::get()->connect();
    //
    $insertDemo = new PostgreSQLPHPInsert($pdo);

    // insert a stock into the stocks table
    $id = $insertDemo->insertStock('MSFT', 'Microsoft Corporation');
    echo 'The stock has been inserted with the id ' . $id . '<br>';

    // insert a list of stocks into the stocks table
    $list = $insertDemo->insertStockList([
        ['symbol' => 'GOOG', 'company' => 'Google Inc.'],
        ['symbol' => 'YHOO', 'company' => 'Yahoo! Inc.'],
        ['symbol' => 'FB', 'company' => 'Facebook, Inc.'],
    ]);

    foreach ($list as $id) {
        echo 'The stock has been inserted with the id ' . $id . '<br>';
    }
} catch (\PDOException $e) {
    echo $e->getMessage();
}

The class of the connection file that "Connection" works without problems (use PostgreSQL \ Connection as Connection;) but use PostgreSQL \ PostgreSQLPHPInsert as PostgreSQLPHPInsert; I get the error that I copied above
This is my autoload.php

<?php

// autoload.php @generated by Composer

require_once __DIR__ . '/composer/autoload_real.php';

return ComposerAutoloaderInit4a8bb4024109306e38c15d9bc0c30d94::getLoader();

This is my class that I do the insert

/**
     * Return all rows in the stocks table
     * @return array
     */
    public function all() {
        $stmt = $this->pdo->query('SELECT id, symbol, company '
                . 'FROM stocks '
                . 'ORDER BY symbol');
        $stocks = [];
        while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
            $stocks[] = [
                'id' => $row['id'],
                'symbol' => $row['symbol'],
                'company' => $row['company']
            ];
        }
        return $stocks;
    }

I have other php with other classes that do not give me error and I do not see difference with this





--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php