Array index changes case when connecting to MySQL on Windows, but not on Linux - php

When I connect my local working copy (Windows 7, WAMP, Apache 2.2, MySQL 5.1, PHP 5.3, CakePHP 2.4) to the local MySQL database, it gives me the following error:
Notice (8): Undefined index: Asset [APP\Controller\AssetsController.php, line 241]
Note, when connecting to the remote RHEL MySQL 5.1 server, the issue does not present itself.
Code in question:
Line 241: 'EnvironmentDeploymentStatus.asset_id'=>$conf['Asset']['asset_id'],
When connected to the RHEL MySQL 5.1, doing var_dump($conf), I'll get this:
array (size=3)
'Asset' =>
array (size=6)
When connected to the localhost Windows MySQL 5.1, doing var_dump($conf), I'll get this (notice the case change in the array key):
array (size=3)
'asset' =>
array (size=6)
The view that populates $conf contains this:
...
from
(((((((`assets` `asset`
...
I put in the following configuration in my local MySQL's my.ini file:
lower_case_table_names=2
The tables are already in lower case (and meet CakePHP standards), I don't think this has any impact on what I'm doing however.

the lower_case_table_names = 2 is probably your problem. It says in the docs
This option also applies to database names and table aliases.
(emphasis added)
MySQL Doc on lower_case_table_names
Which means MySQL is changing the table alias provided by Cake to its lowercase version.
The solution is to set this value back to recommended value of 1.

Related

PDO mysqlnd; Undefined constant PDO::MYSQL_ATTR_READ_DEFAULT_GROUP

I have a LAMP stack, and I thought it might be nice to use the MySQL configuration file to allow PDO to connect to the MySQL database without the need to place DB credentials within our code structure
So I created a group in /etc/my.cnf.d/gggg.cnf
[clientGggg]
user=uuuu
password=pppp
database=dddd
and can now connect to the DB through the command line with mysql --defaults-group-suffix=gggg
I then tried to create a test DB connection in PHP with
$db = new PDO("mysql", null, null, [PDO::MYSQL_ATTR_READ_DEFAULT_GROUP => 'gggg']);
but I received the error
Undefined constant PDO::MYSQL_ATTR_READ_DEFAULT_GROUP
Checking the PDO docs for this attribute reveals the following:
PDO::MYSQL_ATTR_READ_DEFAULT_GROUP (int)
Read options from the named group from my.cnf or the file specified with MYSQL_READ_DEFAULT_FILE. This option is not available if mysqlnd is used, because mysqlnd does not read the mysql configuration files.
and checking my phpinfo(); reveals I am indeed using mysqlnd
Why is this limitation in place? Is there a workaround? Or am I doomed to write/load my credentials into PHP?

Second Database Not configured Error in Laravel 5.3

Friends, I am trying to develop a package in Laravel 5.3 release by using two databases within the host. The first, default, db connects to users table for all authentication and the second is specific to client. I may have many clients and each client will have his own set of tables within the host. It can be done in a single db but i am trying to do this for a specific reason.
The problem is i am getting an error that Dabatabase [18547383] not configured but it is configured and present in the system. The top of backtrace is reproduced below.
in DatabaseManager.php line 242
at DatabaseManager->getConfig('18547383') in DatabaseManager.php line 160
at DatabaseManager->makeConnection('18547383') in DatabaseManager.php line 68
at DatabaseManager->connection('18547383') in Model.php line 3351
at Model::resolveConnection('18547383') in Model.php line 3317
Upon probing a bit in the DatabaseManager.php, at line 240, I have tried to introduce an error to see the data present in the config array.
Strangely, all three named (defined in config) connections viz. mysql, mysql2 and pgsql have the same array values. In fact the pgsql configurations have not been populated in the config file yet they have the same values as that of the default. Hence, it is not finding the second db in the array and hence the error.
The question is, is it a bug in L5.3 ? how can I correctly populate the database connections so that it recognizes the second database.

Laravel sqlite saying the database is "encrypted or is not a database"

I have a database file on my computer called testing.sqlite, which contains a copy of me database that I want to use for testing (rather than connecting to my ordinary MySQL production server).
I created an entry in the config/database file in laravel as instructed, setting it to access the sqlite file, and it all look right. But when I try and actually do anything, I get the error message:
[Illuminate\Database\QueryException]
SQLSTATE[HY000]: General error: 26 file is encrypted or is not a database (SQL: select * from sqlite_master where type = 'table' and name = vendor_alerts)
I can access the file using sqlite testing.sqlite from the command line, why can't laravel read it?
The problem is that the version of sqlite is different. Laravel uses sqlite3, wheareas the sqlite command on your console might be an earlier version. Run sqlite -version from the command line to check your version - is is probably 2 something. You need to install sqlite3, and you'll find that it is not compatible - i.e. sqlite3 testing.sqlite will produce the same error you are getting from laravel.
So, upgrade your command line sqlite version, and copy the data into a new sqlite3 database, and laravel will work without trouble.

Transferring a system built in php(with cakephp) to the other server

I want to transfer a system to the other server with the deterioration of the server that a certain system works.
After transferring a program file and a database to a new server, an error occurs.
■Error contents
Warning (2): pg_query() [function.pg-query]:
Query failed: ERROR: An input sentence structure of model integer is invalid: "\x3234"
LINE 1: ...Aro0"."model" = 'User' AND "Aro0"."foreign_key" = '\x3234' ...
^ [CORE\cake\libs\model\datasources\dbo\dbo_postgres.php, line 148]
※Original Message(in japanese) : Query failed: ERROR: 型integerの入力構文が無効です: "\x37"
For environment
(former)
PHP: 5.2.13
CakePHP: 1.2.7
Apache: 2.2.15
Postgre: 8.4.4-1
(newly)
PHP: 5.5.15
CakePHP: 1.2.7
Apache: 2.4.10
Postgre: 9.2.9.1
I copied a program file from an old server after installation of PHP and Apache and PostgreSQL.
※I changed the connection server to the new server in database.php
※I describe php.ini, httpd.conf to become the setting same as an old server
Login screen (index.php) coming to be displayed,
and inputting ID and a password, and running login processing, the errors occurred.
The real error is ""foreign_key" = '\x3234'" part
that only numerical value guesses character string called"'\x3234'" right in foreign_key.
Only the number to 2 figures is really registered with the item equal to foreign_key even if I confirm a database.
Foreign_key which the login user has is "24",
but seems to be treated in one of login processing as "'\x3234'".
After doing it I tryed to login in other login users,
9 ⇒ '\x39'
7 ⇒ '\x37'
23 ⇒ '\x3233'
24 ⇒ '\x3234'
The left is foreign_key, and the right is really used by SQL.
A head has "\x3", and there seems to be "3" before the second column when there are two columns.
Is there any differents for settings of PHP/CAKEPHP/APACHE/POSTGRESQL ?

Attempting to use index type '-1' where index types are not allowed (1 or -1 only)

I am using:
$db->collection->find()->sort(array('username' => '-1'));
And I keep getting the error:
MongoCursorException: localhost:27017: Attempting to use index type
'-1' where index types are not allowed (1 or -1 only).
I am using MongoDB 2.4.1 with PHP driver 1.3.x.
Why is this?
You have called sort like so:
sort(array('username' => '-1'));
Which is a problem. In MongoDB 2.4.1 there is a slight quirk (bug?) which means that it will not accept strings any more for sort ordering.
Since this is not in the driver but instead in the server (MongoDB itself) simply changing driver version will not fix this.
This could have existed earlier than MongoDB 2.4.1 however, I merely tested this on MongoDB 2.0.0 and 2.1.x whereby I did not observe this behaviour on the same PHP driver version (1.2.x and 1.3.x).
To fix this you must specify a signed numerical figure like so:
sort(array('username' => -1));
That will work.
Edit
After posting in the mongodb-user Google group, I found out this was not a bug, however, it is still something to be aware of.

Categories