Cakephp 3 Bake all issue with MSSQLSRV - sql-server

I am using Cakephp 3 and MSSQLSRV 2014. I made all the necessary changes to connect to MSSQL server. In GUI, I can see that cakephp can connect to MSSQL. Please see the below screenshot.
So now when I go to bin directory to bake the application, I get below error unable to load MSSQL driver, which is already installed:
Here are my datasource settings in app.php file:
'Datasources' => [
'default' => [
'className' => 'Cake\Database\Connection',
'driver' => 'Cake\Database\Driver\Sqlserver',
'persistent' => false,
'host' => 'localhost\SQLEXPRESS',
/**
* CakePHP will use the default DB port based on the driver selected
* MySQL on MAMP uses port 8889, MAMP users will want to uncomment
* the following line and set the port accordingly
*/
'port' => '1433',
'username' => 'sa',
'password' => 'password',
'database' => 'ServerMatrix',
'encoding' => 65001,
'timezone' => 'UTC',
'cacheMetadata' => true,
'log' => false,
I am thinking its probably a bug that should be reported to CakePHP community, but wanted to get some help from stack-overflow community to see if they have encountered such issue.

In command line interface typed php --ini and opened loaded php.ini file and added SQLSrv extensions. That solved the problem for baking an application.
Thanks to #ndm.

Related

Error on upgrade to 3.7: Property _transportConfig does not exist

Upgraded CakePHP from 3.5 -> 3.6 -> 3.7. The error message, Property _transportConfig does not exist, is displayed as soon as the application starts in the browser.
Email Transport config in app.php
'EmailTransport' => [
'default' => [
'className' => 'Smtp',
'host' => 'smtp.gmail.com',
'port' => 587,
'username' => '*******#gmail.com',
'password' => '********************',
'log' => true,
'tls' => true
],
],
I've found some information in the migration guide, here is a solution that may work;
First, you need to add this to your bootstrap file
use Cake\Mailer\TransportFactory;
then replace
Email::setConfigTransport(Configure::consume('EmailTransport'));
by
TransportFactory::setConfig(Configure::consume('EmailTransport'));
finally you might consider updating the debugger via composer :
λ composer require --update-with-dependencies "cakephp/debug_kit"
Might not be the best way to, but it worked for me!

DebugKit in cakephp 3.x do not show DebugKit Toolbar

DebugKit Toolbar do not show at the top-right of my localhost/thegioididong page.
Try:
bin/cake plugin assets symlink
to load debugkit assets.
SOLVED! I do these thing:
1: check the debug status at the top of config\app.php.
`'debug' => filter_var(env('DEBUG', true), FILTER_VALIDATE_BOOLEAN),`
2: add to the end of config\bootstrap.php these codes:
`if (Configure::read('debug')) {
Plugin::load('DebugKit', ['bootstrap' => true]);
}`
3: create debug_kit table in mysql database - leave it empty database (localhost/phpmyadmin - in my case), then add:
'debug_kit' => [
'className' => 'Cake\Database\Connection',
'driver' => 'Cake\Database\Driver\Mysql',
'persistent' => false,
'host' => 'localhost',
'username' => 'root',
'password' => 'root1234',
'database' => 'debug_kit', //leave it empty - without tables
'encoding' => 'utf8',
'timezone' => 'UTC',
'flags' => [],
'cacheMetadata' => true,
'log' => false,
'quoteIdentifiers' => false,
'url' => env('DATABASE_URL', null),
],
into config\app.php following this structure:
'Datasources' => [
'default' => [
//default database config here
],
'debug_kit' => [
//debug_kit database config as above
],
'test' => [
//test database config here
],
],
Thanks a lot. I'm sory for my English!
in my case cake 3.5 this lines of code work
if (Configure::read('debug')) {
Configure::write('DebugKit', ['forceEnable' => true]);
Plugin::load('DebugKit', ['bootstrap' => true]);
}
add this line at the end of bootstrap.php
Do you have this in your bootstrap.php file?
if (Configure::read('debug')) {
Plugin::load('DebugKit', ['bootstrap' => true]);
}
enabled sqlite, for linux mint
nano /etc/php/7.2/apache2/php.ini
uncomment
extension=sqlite3
restart apache
service service apache2 restart
For CakePHP 3.x:
Check if "debug" is set to true. You may add debug('test'); somewhere in your app and check if you see the word "test" in your website's code at the beginning.
Check that debugkit plugin is loaded by adding debug(Plugin::loaded('DebugKit')); at the end of bootstrap.php. This should echo "true".
Add Configure::write('DebugKit', ['forceEnable' => true]); before you load DebugKit.
Add your development TLD to the "safeTld" property. (thanks #mark)
// Allow e.g. http://foo.bar.dev or http://my-shop.local domains locally
Configure::write('DebugKit.safeTld', ['dev', 'local', 'example']);
Copy or symlink asset plugins running bin/cake plugin assets symlink (use copy on windows)
Docs here.
Make sure you have sqlite extension installed. If you're using Laragon, enable Sqlite extensions in Menu > PHP > Extensions (this is what fixed my issue).

CakePHP 3 ORM : Cache metadata issue

I'm working on a project which only a few packages of cake 3 :
cakephp/orm
cakephp/validation
cakephp/i18n
cakephp/cache
I just installed the last one (cache).
I uploaded my project to a production server, and was surprised to see that my queries using the ORM are extremely slow (a query that lasts about 100ms on my local machine can take up to 5 or 10 seconds on the production server).
It seems that there are queries on the information_schema table that take much time and resources. So I've went on the web and saw that I needed the enable cacheMetaData param in my config.
My config looks like this :
ConnectionManager::config('default', [
'className' => 'Cake\Database\Connection',
'driver' => 'Cake\Database\Driver\Mysql',
'host' => 'my-host',
'database' => 'my-database',
'username' => 'my-username',
'password' => 'my-password',
'encoding' => 'utf8',
'timezone' => 'UTC',
'cacheMetaData' => true // If set to `true` you need to install the optional "cakephp/cache" package.
]);
I followed the instruction above and installed the cakephp/cache package. But I'm guessing I need to enable it somehow (or somewhere), but can't figure out how (or where).
Here is what I tried :
\Cake\Cache\Cache::config('_cake_model_', [
'className' => 'File',
'prefix' => 'myapp_cake_model_',
'path' => '/cache/models/',
'serialize' => true,
'duration' => '+2 minutes',
]);
But it's still not working, my cache or cache/models/ folder is still empty and the requests are taking a long time.
How can I fix this ?
Thanks for your time
kinkaz
For a detailed solution on this topic, please see http://discourse.cakephp.org/t/orm-cache-metadata-issue/1071

cakephp error. Connection to database ...not ...: Access denied for user 'my_app'#'localhost' (using password: YES)

I am trying to start CakePHP. I made bookmarker and tested by command bin\cake server. It showed one error as connection to database could not be established:
SQLSTATE[HY000] [1045] Access denied for user 'my_app'#'localhost' (using password: YES).
I read the config/app.default.php file. It says there is a database my_app and another database test_myapp with some users. I can not find these databases in phymyadmin in xampp. Am I supposed to create the named databases and users manually? I thought CakePHP should create these automatically. Or should I give names of databases etc. which I like and create the same.I'm using xampp with windows 7 and am very new to CakePHP.
Cake will not create the database or database user for you. You need to create them yourself and then match these database credentials into the db config file. Your datasource in app/Config/app.php file should look something similar to:
'Datasources' => [
'default' => [
'className' => 'Cake\Database\Connection',
'driver' => 'Cake\Database\Driver\Mysql',
'persistent' => false,
'host' => 'localhost',
'username' => 'my_db_user',
'password' => 'my_db_user_password',
'database' => 'cake_database_name',
'encoding' => 'utf8',
'timezone' => 'UTC',
'cacheMetadata' => true,
]
],
In this example you would have to create a database named: cake_database_name, and then add a database user named my_db_user with the password of my_db_user_password.
Edit Config/app_local.php file instead of Config/app.php with your database connection parameters, i.e. host, username, password, database name. This will solve the problem.
Be sure to create same database first and providing enough privileges to same user you're writing in app_local.php file.
See in Mysql.php:
class Mysql extends Driver
{
use MysqlDialectTrait;
use PDODriverTrait;
/**
* Base configuration settings for MySQL driver
*
* #var array
*/
protected $_baseConfig = [
'persistent' => true,
'host' => 'localhost',
'username' => 'root',
'password' => '',
'database' => 'cake',
'port' => '3306',
'flags' => [],
'encoding' => 'utf8',
'timezone' => null,
'init' => [],
];
Then in app.php write
'Datasources' => [
'default' => [
'className' => 'Cake\Database\Connection',
'driver' => 'Cake\Database\Driver\Mysql',
'persistent' => false,
'host' => 'localhost',
/**
* CakePHP will use the default DB port based on the driver selected
* MySQL on MAMP uses port 8889, MAMP users will want to uncomment
* the following line and set the port accordingly
*/
//'port' => 'non_standard_port_number',
'username' => 'root',
'password' => '',
'database' => 'cake',
'encoding' => 'utf8',
'timezone' => 'UTC',
'flags' => [],
'cacheMetadata' => true,
'log' => false,
...],
In phpMyAdmin
create cake database.
It's all.
Edit Config/app_local.php file with your database connection parameters. You will find host, username, password, database name their.
don't edit config/app.php with database connection parameters.
Your problem will be now solved
CakePHP 4.x
Error:
SQLSTATE[HY000] [1045] Access denied for user 'my_app'#'localhost'
(using password: YES).
Reason:
No user id: "my_app" with password: "secret" [or any other] set in config/app.php
file.
Solution:
In case of WAMP, go to phpmyadmin page, then we can select cake_cms
database -> privilage-> create user id and password, same as in config
file config/app.php, refresh the http://localhost:8765/ page.
it should now show
CakePHP is able to connect to the database.
If you are using wamp, make sure port is uncomment in Datasources and 'port' => '3308'
I solved this problem by checking port at phpmyadmin top
and uncommit below line in app_local.php
'port' => '3308',
CakePHP3.9.3,app_local.php,'username`=>'root','password'=>'','database' => 'db name'

CakePHP 2.3 with SqlServer on debian squeeze

I'm confused about all the requirements to get cakephp 2.x to talk to MSSQL (2k8R2). I'm running debian squeeze and installed php5-sybase.
I'd be using this as a second datasource defined as
public $qadb = array(
'datasource' => 'Database/Sqlserver',
'persistent' => false,
'host' => 'xxx.xxx.xxx.xxx',
'login' => 'myuser',
'password' => 'mypass',
'database' => 'mydb',
'prefix' => '',
//'encoding' => 'utf8',
);
When I'm trying to run cake bake with this datasource I get
Error: Database connection "Sqlserver" is missing, or could not be created.
I looked at http://www.php.net/manual/en/ref.pdo-sqlsrv.php which references installing ODBC for linux, but I thought the sybase package would take care of what I need. Any further info anyone has on this would be appreciated.

Resources