Question

I installed composer in my CodeIgniter project, downloaded 2 packages: Aura/Sql and Aura/SqlQuery

this is my code from index.php file

require_once ROOTPATH . 'vendor/autoload.php';

use Aura\Sql\ExtendedPdo;
$db = new ExtendedPdo('mysql:host=127.0.0.1;dbname=mydb', 'root', '', array(), array());
var_dump($db->fetchAll('SELECT * FROM sh_users'));

use Aura\Sql_Query\QueryFactory;
$query_factory = new QueryFactory('mysql');

require_once BASEPATH . 'core/CodeIgniter.php';

both fragments are copied from documentation

var_dump gives perfect result, but QueryFactory gives me error

Fatal error: Class 'Aura\Sql_Query\QueryFactory' not found in F:\XAMPP\htdocs\codeigniter\public\admin\index.php on line 83

and i have no idea why. all vendors are downloaded and all php files are there, but it seems autoload doesnt load it. why?

Was it helpful?

Solution

Take a look at the file structure on disk; you may actually want to be including Aura\SqlQuery\QueryFactory, instead of something under the Sql_Query namespace. It may be something as simple as that. I've encountered issues when I've forgotten to rename the class in a PSR-0 compliant path such that it matches the file name, so if in fact the contents on the disk are in:

Aura\SqlQuery\QueryFactory but your use statement is Aura\Sql_Query\QueryFactory, you'll run into a problem.

As mentioned below in the comments, it appears that the Aura devs have two branches, the master branch on the Githup project auraphp/Aura.Sql_Query still has the directory structure as Sql_Query where as the default package, served by packagist, serves the dev-rename branch which replaces Sql_Query with SqlQuery.

Hope that helps!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top