Error connecting PHP ActiveRecord with XAMPP phpmyadmin

0

When trying to connect phpactiverecord to the database in phpmyadmin XAMPP by means of this code:

<?php

require_once 'php-activerecord/ActiveRecord.php';

$cfg = ActiveRecord\Config::instance ();
$cfg->set_model_directory ( 'model' );
$cfg->set_connections ( array ('development' => 'mysql://root@localhost/phpmyadmin/dbaqua') );

You receive the following error message:

Fatal error:
Uncaught exception 'ActiveRecord\DatabaseException'
with message
  "exception 'PDOException'
   with message 'SQLSTATE[HY000] [1049] Unknown database 'phpmyadmin/dbaqua'"
in C:\xampp\htdocs\BancoAQUA\service\library\php-activerecord\lib\Connection.php:202
>Stack trace:
>0 C:\xampp\htdocs\BancoAQUA\service\library\php-activerecord\lib\Connection.php(202): PDO->__construct('mysql:host=loca...', 'root', NULL, Array)
>1 C:\xampp\htdocs\BancoAQUA\service\library\php-activerecord\lib\Connection.php(99): ActiveRecord\Connection->__construct(Object(stdClass))
>2 C:\xampp\htdocs\BancoAQUA\service\library\php-activerecord\lib\ConnectionManager.php(33): ActiveRecord\Connection::instance('development')
>3 C:\xampp\htdocs\BancoAQUA\service\library\php-activerecord\lib\Table.php(83): ActiveRecord\ConnectionManager::get_connection(NULL)
>4 C:\xampp\htdocs\BancoAQUA\service\library\php-activerecord\lib\Table.php(61): ActiveRecord\Table->__construct('UsuarioModel')
>5 C:\xampp\htdocs\BancoAQUA\service\library\php-activerecord\lib\M in C:\xampp\htdocs\BancoAQUA\service\library\php-activerecord\lib\Connection.php on line 204

How can this be fixed? Thank you in advance.

UserModel:

<?php

require_once 'settings/config.php';

class UsuarioModel extends ActiveRecord\Model {
    static $table_name = 'tdusuario';
}
    
asked by anonymous 25.02.2016 / 18:27

1 answer

2

phpmyadmin is NOT a database , it is only a manager, its PHP applications do not control it, since it is already an application and is not used by the end user of an application used only by those who manage the bank to facilitate "maintenance".

I recommend you read:

The mysql: protocol does not access urls like http, which seems like what you tried in mysql://root@localhost/phpmyadmin/dbaqua

According to the link documentation the correct one is:

  

mysql: // [USER]: [PASSWORD] @ [HOST] / [BANK NAME]

So if your bank name is dbaqua :

<?php
require_once 'php-activerecord/ActiveRecord.php';

ActiveRecord\Config::initialize(function($cfg)
{
    $cfg->set_model_directory('models');
    $cfg->set_connections(array(
        'development' => 'mysql://root@localhost/dbaqua')
    );
});
  

Note: Xampp is not a server, it is a package that comes with Apache (this is the server) + PHP + mysql, you do not connect to Xampp, you connect to Apache or Mysql (depends on what What are you doing?

    
25.02.2016 / 18:47