How can I move my codigniter databse to google cloud sql? - php

I want to move my codeigniter project database to google cloud sql but I didn't see phpmyadmin.
How can i export my database to google and where do i get myconnection details, host,password,user and dbname just like I have on my local server?
The documentation is not very clear to someone who is not familiar with that environment. Thanks
This is my database config file
$active_group = 'default';
$query_builder = TRUE;
$db['default'] = array(
'dsn' => '',
'hostname' => '104.197.147.157',
'username' => 'mylasttestingaccount',
'password' => '',
'database' => 'mydatabase',
/*
'username' => 'develope_prakash',
'password' => '[REDACTED]',
'database' => 'develope_ubah',
*/
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => FALSE,
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);

This is a multipart question, so I'll answer the questions as I understand them.
NOTE: Cloud SQL instances are not managed using phpmyadmin, but they are managed mainly using the Cloud Console. This also means that whatever changes you want to make (such as adding users) needs to be done using the Cloud Console, or from one of the other management tools such as the gcloud command line tool.
1) You'll need to create an instance first. I highly advise a 2nd gen instance.
2) Adding a user can be done from the Console or the gcloud command line tool. Both are described in the same article.
3) As for importing data from another database, there's a separate article on this. There's some conditions that need to be met before you can successfully import data. The export needs to be created in a certain way. This is described in detail in this article. After getting the export you can import it using the steps described in the first article I linked in this paragraph.
To wrap it up, I highly advise you to read through the documentation about Cloud SQL. Any of the ones I linked have a list of articles on the left side which contains just about everything you need to know about Cloud SQL.
One additional note, NEVER provide passwords for anything on a public site like SO.

Related

What is the correct way to apply the yii2 cache?

As I'm new to the cache mechanism, I gone through the yii2 documentation. As per the documentation, I added the below config in db.php in yii2 basic application.
<?php
return [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=db_new',
'username' => 'root',
'password' => 'root123',
'charset' => 'utf8',
'enableQueryCache' => true,
'queryCacheDuration' => 86400,
'enableSchemaCache' => true,
// Name of the cache component used to store schema information
'schemaCache' => 'cache',
// Duration of schema cache.
'schemaCacheDuration' => 86400, // 24H it is in seconds
];
also I added the cache component in web.php
'components' => [
'cache' => [
'class' => 'yii\caching\ApcCache'
]
]
And added the below code while retrieving a record from clients table.
$db = Clients::getDb();
$client = $db->cache(function ($db)use($id) {
return Clients::find()->where(['id' => $id])->all();
});
I assume my client table one record ex)$id = 3 is cached. So next time if I try to retrieve same record from clients table it will pull from cache not from scratch.
My questions are
What I did above is this correct or anything I need to configure
more?
Where it is storing in the local system.
Thanks in advance.
what you did is correct for query caching, found in data caching here.
there are more caching mechanisms available, like fragment, page or http caching
as far as i know, the place where the cached data is stored depends on the caching component. apc stores in memory
yii's FileCache will store files under /runtime
good to know you can flush caches with yii's console command yii cache/flush-all

Migrating existing cakephp 3.0 database to postgres from mysql

I am in the process of migrating a cakephp 3.0 database from mysql to postgress. I used this tool for the database migration and it worked beautifully. After that I changed the config file as shown below.
'default' => [
'className' => 'Cake\Database\Connection',
'driver' => 'Cake\Database\Driver\Postgres',
'persistent' => false,
'host' => 'localhost',
'port' => '5432',
'username' => 'postgres',
'password' => 'mypass',
'database' => 'cake_bookmarks',
'encoding' => 'utf8',
'timezone' => 'UTC',
'cacheMetadata' => true,
'log' => false,
'quoteIdentifiers' => false,
//'init' => ['SET GLOBAL innodb_stats_on_metadata = 0'],
],
The root folder in localhost also shows "successfully connected to database". However when i run my application, it shows an error:
Cannot describe mytable. It has 0 columns. Cake\Database\Exception
I can't make sure if this is because of not connecting to the database (which i think is unlikely as the root page shows as connected) or cakephp being unable to use my database.
If so, how can I fix the issue. I am quite new to cakephp too, just confguring and doing basic stuff.
Try the following (test after each step):
Check if the table is present in the database
Check if the expected columns are defined into the table
Clear the Cake cache (if is FileCache is enough to delete files under tmp/cache/persistent tmp/cache/models and tmp/cache/views
Check the permissions of the specific user on the database cake_bookmarks (maybe via phppgadmin)
Hope to help!

CakePHP merge multi apps,one database and multi domain to access

The Situation
Currently, there are two separate cakePHP projects(apps) where implementation is done and running smoothly of course with different database.
Now, the requirement is to merge these two separate cakePHP apps into one with same database and to run on different domains.
The Problem
1)There exists two different login functions which should be one after merging.Like this there may be some other huge code should be written common.
So, please provide solution or direct me to right way how can one manage common code for multiple apps with different domain
e.g., https://www.sample-1.com/login
and https://www.sample-2.com/login
which is using same database to validate users.
2) How to distinguish routes?
3) How to manage such projects which will grow later?
For both domian you may call common database file and common app folder.
Then you can switch database depends upon request action
Try this
if (isset($_SERVER) && isset($_SERVER['SERVER_NAME'])) {
if (strpos($_SERVER['SERVER_NAME'], 'localhost') === false) {
$config = ConnectionManager::getDataSource('defaultCompany')->config;
}
}
inside database.php file
var $defaultCompany = array(
'driver' => 'mysql',
'persistent' => false,
'encoding' => 'utf8',
'host' => 'localhost',
'login' => '',
'password' => '',
'database' => '',
'prefix' => '',
'port' => '',
);
Or if you want common file in both domain. Create plugins outside app folder directory and put inside it.

Problems loading Zends Session in bootstrap

I am having trouble getting Zend to store my session in MySQL table. I have followed the Zend Framework guide step by step, and am not sure if is where am putting the code in my bootstrap file, but once the code snippet is in place and I load my site Apache just crashes. Literally crashes. My logs don't say anyhing.
Here is my code:
$db = Zend_Db::factory( 'Pdo_Mysql', array(
'host' => 'localhost',
'username' => 'root',
'password' => '*****',
'dbname' => 'drecords'
));
Zend_Db_Table_Abstract::setDefaultAdapter( $db );
$config = array(
'name' => 'sessions',
'primary' => 'id',
'modifiedColumn' => 'modified',
'dataColumn' => 'data',
'lifetimeColumn' => 'lifetime'
);
Zend_Session::setSaveHandler( new Zend_Session_SaveHandler_DbTable( $config ) );
//start your session!
Zend_Session::start();
I am running this code right after at the end of my Bootstrap file.
My question is what am I doing wrong if am following Zends documentation? Is there something I need to know like an extra configuration option in my MySQL or PHP.ini that am not aware of?
Did you create the table in MySQL?
your user have insert/update/delete privileges on the table
do your php setups output errors, what environment are your running production/development
I think the code should probably output some error but if your disabled the output of those you cannot see them.

cakephp : separate database access for admin users

I have been using cakephp for creating web application. In my current project there are two database users one for admin another for site users, how can I configure cakephp so that the admin can login to the site with more database operations power ?
Thank you
I agree. Sometimes, it's better having permissions handled in your application layer than the database layer. However, if you really, really want to have that extra layer of security in your database as well, then you should set up multiple database connections:
var $default = array(
'driver' => 'mysql',
'persistent' => false,
'host' => 'localhost',
'login' => 'normaluser',
'password' => '',
'database' => 'db',
'prefix' => '',
);
var $admin = array(
'driver' => 'mysql',
'persistent' => false,
'host' => 'localhost',
'login' => 'adminuser',
'password' => '',
'database' => 'db',
'prefix' => '',
);
You can then use $this->ModelName->setDataSource('admin') if the user is in the admin section, or whatever condition that you might impose.
I would suggest that you look at the admin_ prefix routing. CakePHP lets you handle admin powers quite easily. Prefix Routing Additionally, you can add a field in your users table to indicate the role of the user, and check that against the current prefix.
the most robust solution will likely be setting up Access Control Lists(ACLs). This will allow you to delegate permissions based on a user role that you designate.
For example admin has a group_id of 1, and users have a group_id of 2. Then you can allow admins to have access to certain operations within your web app.
Here's the cake documentation on this feature.
http://book.cakephp.org/view/1242/Access-Control-Lists

Categories