using "CDbAuthManager" generates exception "CPhpAuthManager" is not defined - php

Hi I am tring to implement RBAC to an application . I set auth manager to CDbAuthManager:
'db'=>array(
'connectionString' => 'mysql:host=localhost;dbname=blog',
'emulatePrepare' => true,
'username' => 'root',
'password' => '',
'charset' => 'utf8',
),
'authManager'=>array(
'class'>'CDbAuthManager',
'connectionID' => 'db',
),
and when I use
$auth = Yii::app()->authManager;
it generates " Property "CPhpAuthManager.0" is not defined. "
I checked db connection and i am able to do crud . what am I doing wrong ?

I found that tables names was case sensitive. modified tables names .. all worked

Related

Yii2 dynamic connection to second database

I have a simple select in my View code. It represents list of cities and on my server there're several databases which are responsible for each city. I have my Model code and it takes city_id. Depends on it I want to connect to database and seek for needed data in it. I've added second database to my components like:
'db' => require(__DIR__ . '/db.php'),
'db2' => require(__DIR__ . '/db_login.php'),
and two files which returns database connection.
File 1:
'class' => 'yii\db\Connection',
'dsn' => $dsn,
'username' => $username,
'password' => $password,
'charset' => 'utf8',
File 2:
'class' => 'yii\db\Connection',
'dsn' => $dsn,
'username' => $username,
'password' => $password,
'charset' => 'utf8',
I want to change my database name somehow dynamically right after users' choice.
You can do a call for dbconnection
$actual_dsn = 'your_dns_actual_value'
$yourConnection = new \yii\db\Connection([
'dsn' => $actual_dsn,
'username' => $username,
'password' => $password,
]);
$yourConnection->open();
eventually close the previous open connection
You can do this in your db_login.php depending of the application's needs
Maybe :
if (choice =='a') {
'db' => require(__DIR__ . '/db.php')
}
else {
'db2' => require(__DIR__ . '/db_login.php')
}

Kohana 3.3 Database::instance('name') not working

I have an issue with Kohana 3.3 and using different database configurations.
I have a config/database.php with 'default' config and 'other' like this:
return array
(
'default' => array
(
'type' => 'MySQL',
'connection' => array(
'hostname' => 'localhost',
'database' => 'database-one',
'username' => 'root',
'password' => 'password',
'persistent' => FALSE,
),
'table_prefix' => '',
'charset' => 'utf8',
'caching' => FALSE,
),
'other' => array
(
'type' => 'MySQL',
'connection' => array(
'hostname' => 'localhost',
'database' => 'database-two',
'username' => 'root',
'password' => 'password',
'persistent' => FALSE,
),
'table_prefix' => '',
'charset' => 'utf8',
'caching' => FALSE,
));
But in a Controller or Model when trying to use:
Database::instance('other');
Kohana will still use the 'default' configuration. What am I doing wrong?
Thanks!
If you would like to change currently used connection by kohana try this:
Database::$default = 'other';
From this line your code will use 'other' connection till you will switch it again to 'default' using same way.
You can also use another DB configuration once when executing the query in simple way:
DB::...->execute('other');
Or if you store your DB instance earlier:
$other = Database::instance('other');
DB::...->execute($other);
By ... I mean your query.
You need to store the connection in a variable, or the default connection will be used.
Documentation

doctrine 2 create database and tables [duplicate]

I would like to create a database with doctrine 2 and zend framework 2.
I tried to use the command line but it doesn't work because first of all I need to be connected to a database.
Here is the command line that I could use :
When I use the command "php doctrine dbal:run-sql CREATE DATABASE TOTO", I receive an error which tells me that I the database that I selected (but I don't want to select any database) is unknown.
Do you have any idea how I can figure out this problem ?
I really appreciate if I not obliged to use phpmyadmin and create it by my own. I'll prefer to use doctrine to make sure that my code is compatible with other kind of database (such as Mysql/Postegre)
Thank you =D
I found the solution.
You just have to specify in your configuration file that the dbname is equals to null.
<?php
return array (
'doctrine' => array (
'connection' =>
array (
'orm_default' =>
array (
'driverClass' => 'Doctrine\\DBAL\\Driver\\PDOMySql\\Driver',
'params' =>
array (
'host' => 'localhost',
'port' => '3306',
'user' => 'root',
'password' => '',
'dbname' => null,
'charset' => 'UTF8',
),
),
'orm_poems' =>
array (
'driverClass' => 'Doctrine\\DBAL\\Driver\\PDOMySql\\Driver',
'params' =>
array (
'host' => 'localhost',
'port' => '3306',
'user' => 'root',
'password' => 'mot de passe',
'dbname' => 'poemsV3',
'charset' => 'UTF8',
),
),
),
),
);
Have a good day everybody =D

How do I set table prefix in Yii

In a project I am working on I need to set a table prefix for the project which I can change later. Browsing through the docs I came across this :
http://www.yiiframework.com/doc/api/1.1/CDbConnection#tablePrefix-detail
But it is not explained where I implement this. I mean should I put it in protected/config/main.php or edit the core files ?
You put it in the config file, along with other db configuration, like this:
'db'=>array(
'connectionString' => 'xxxxx',
'username' => 'xxxxx',
'password' => 'xxxxx',
'tablePrefix' => 'tbl_',
),
All public properties of any component can be set in the config file this way.
'db'=>array(
'connectionString' => 'mysql:host=localhost;dbname=###',
'emulatePrepare' => true,
'username' => '###',
'password' => '###',
'charset' => '###',
'tablePrefix' => 'r_',
),

configuring database connection in Yii framework

In the main.php file of the Yii framework, there are some configuration options. This is how it sets up mysql
'db'=>array(
'connectionString' => 'mysql:host=localhost;dbname=testdrive',
'emulatePrepare' => true,
'username' => 'root',
'password' => 'root',
'charset' => 'utf8',
),
On my MAMP system, I have to specify the port as 8889. How would I add it into this?
thanks
I added the port like this and it seems to work
'db'=>array(
'connectionString' => 'mysql:host=localhost;port=8889;dbname=testdrive',
'emulatePrepare' => true,
'username' => 'root',
'password' => 'root',
'charset' => 'utf8',
),
can you not add it here to your connectionString
'connectionString' => 'mysql:host=localhost;dbname=testdrive;port=8889',

Categories