Error with composer
| From: | Romero, Fernando | Date: | Fri, 23 Mar 2018 11:34:56 +0000 |
| Subject: | Error with composer | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-326410@lists.php.net to get a copy of this message | ||
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