phalcon / cphalcon

High performance, full-stack PHP framework delivered as a C extension.
https://phalcon.io
BSD 3-Clause "New" or "Revised" License
10.79k stars 1.96k forks source link

[BUG]: describeIndexes return unknown index name '\000' #16480

Closed tao996 closed 10 months ago

tao996 commented 11 months ago

Describe the bug

when call the describeIndexes \db()->describeIndexes('demo_article');

CREATE TABLE IF NOT EXISTS `demo_article` (
  `id` int UNSIGNED NOT NULL AUTO_INCREMENT,
  `user_id` int UNSIGNED NOT NULL,
  `title` varchar(50) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

it print the below error

Notice: Undefined index: Key_name in ...
Notice: Undefined index: Index_type in ...
Notice: Undefined index: Column_name in ...
Notice: Undefined index: Non_unique in ...
Notice: Undefined index: columns in ...
Fatal error: Uncaught TypeError: Phalcon\Db\Index::__construct(): Argument #2 ($columns) must be of type array, null given in /var/www/IndexController.php on line 15
TypeError: Phalcon\Db\Index::__construct(): Argument #2 ($columns) must be of type array, null given in /var/www/IndexController.php on line 15

Call Stack
# | Time | Memory | Function | Location
-- | -- | -- | -- | --
1 | 0.2021 | 377984 | {main}( )
...
7 | 0.3829 | 581480 |  describeIndexes( $table = 'demo_article' )  .../IndexController.php:15
8 | 0.4077 | 603392 | __construct( $name = '\000', $columns = NULL, $type = 'UNIQUE' ) 

the question is I don't know where the __construct( $name = '\000', $columns = NULL, $type = 'UNIQUE' ) come from

Details

the docker desktop run in windows 11

Additions Information

/var/www # php -m

Warning: JIT is incompatible with third party extensions that override zend_execute_ex(). JIT disabled. in Unknown on line 0
[PHP Modules]
apcu
bcmath
calendar
Core
ctype
curl
date
dom
exif
fileinfo
filter
ftp
gd
gettext
hash
iconv
imagick
intl
json
libxml
mbstring
mcrypt
memcached
mongodb
mysqlnd
openssl
pcre
PDO
pdo_mysql
pdo_pgsql
pdo_sqlite
phalcon
Phar
posix
random
readline
redis
Reflection
session
SimpleXML
sodium
SPL
sqlite3
standard
tokenizer
xdebug
xml
xmlreader
xmlwriter
xsl
yaml
Zend OPcache
zip
zlib

[Zend Modules]
Xdebug
Zend OPcache

##### php.ini
error_reporting = E_ALL & ~E_DEPRECATED
display_errors = "On"
display_startup_errors = "On"
log_errors = "On"
error_log = /var/log/php/php_errors.log

memory_limit = 16M
allow_url_fopen = Off
allow_url_include = Off
register_globals = Off
max_execution_time = 30
max_input_time = 60
upload_max_filesize = 8M
post_max_size = 8M
max_input_nesting_level = 4
expose_php = Off
cgi.fix_path = 0

fastcgi.logging = 0

zend_extension = opcache.so
opcache.enable = 1
opcache.enable_cli = 1
opcache.jit_debug = 1
opcache.jit = 1255
opcache.jit_buffer_size = 100M

zend_extension = xdebug.so
[xdebug]
xdebug.mode = debug,develop
xdebug.discover_client_host = 0
xdebug.idekey = docker
xdebug.start_with_request = yes
xdebug.client_port = 19003
xdebug.client_host = host.docker.internal
;xdebug.log = /dev/stdout
xdebug.log = /var/log/php/xdebug.log
niden commented 10 months ago

I am going to try and test this with your example. My guess on the:

the question is I don't know where the __construct( $name = '\000', $columns = NULL, $type = 'UNIQUE' ) come from

is when the table has to be created and the primary index is created.

niden commented 10 months ago

@tao996 I used the code you provided as well as the environment. Unfortunately I cannot reproduce this.

The migration where the table is created: https://github.com/niden/cphalcon/blob/T16480-indexes-describe/tests/_data/fixtures/Migrations/EncodingMigration.php#L50

The test I run: https://github.com/niden/cphalcon/blob/T16480-indexes-describe/tests/database/Db/Adapter/Pdo/DescribeIndexesCest.php#L52

The only change I had to do in that branch was to upgrade the mysql version to 8.1 which is identical to the one you are using.

This is the run for the tests:

https://github.com/niden/cphalcon/actions/runs/7455194454

tao996 commented 10 months ago

@niden thank you for your answer very much. I check my code, and find the error

$db = new Phalcon\Db\Adapter\Pdo\Mysql([
    'host'     => 'host.docker.internal',
    'username' => 'demo',
    'password' => '123456',
    'dbname'   => 'phalcon_demo',
    'charset' => 'utf8mb4',
    'collation' => 'utf8mb4_unicode_ci',
    'prefix' => '',
    'options' => [
        \PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'UTF8'",
//        \PDO::ATTR_CASE => \PDO::CASE_LOWER,  // this line cause the error
        \PDO::ATTR_EMULATE_PREPARES => false,
        \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
        \PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC
    ],
]);
niden commented 10 months ago

@tao996 Great to hear. Closing this.