Error when connecting PHP Activerecord with XAMPP phpmyadmin

Asked

Viewed 626 times

0

When trying to connect phpactiverecord to the database in XAMPP phpmyadmin through 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') );

The following error message is received:

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 solved? Thanks in advance.

User:

<?php

require_once 'settings/config.php';

class UsuarioModel extends ActiveRecord\Model {
    static $table_name = 'tdusuario';
}

1 answer

1


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

I recommend you read:

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

According to the documentation http://www.phpactiverecord.org/projects/main/wiki/Quick_Start the correct is:

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

So if the name of your bank 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 you are doing)

  • 2

    Thank you very much!!!

  • @Beatriz has solved herself please mark the answer as correct ;)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.