Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot use a scalar value as an array #11466

Closed
kowach opened this issue Feb 28, 2016 · 7 comments
Closed

Cannot use a scalar value as an array #11466

kowach opened this issue Feb 28, 2016 · 7 comments
Labels
stale Stale issue - automatically closed

Comments

@kowach
Copy link

kowach commented Feb 28, 2016

Problem:
Cannot use a scalar value as an array in phalcon/mvc/model.zep on line 1070
which produces another error "You cannot serialize or unserialize PDO instances"

let num = connection->fetchOne(...)
if num["rowcount"]

if num is scalar then fetchOne returns an object. If database returns object then my default fetch mode is FETCH_OBJ.

$conn = new Phalcon\Db\Adapter\Pdo\Mysql(
...
 'options'  => array(
        PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ
    )
)

If I comment this option, I get no error.

@rlaffers
Copy link
Contributor

rlaffers commented Jun 11, 2017

I have a similar issue. The same error is manifested when calling \Phalcon\Db\Adapter\Pdo::connect() with a connection configuration containing:

        'options' => array(
            \PDO::ATTR_CASE => \PDO::CASE_UPPER
        ),

In fact, as long as options key is present in the config, the error does not go away.
PHP 7.0.19, Phalcon 3.1.2, using Oracle adapter from Incubator.

Stack trace:

"ErrorException: Cannot use a scalar value as an array in  on line 0 in /srv/www/lafo/tm/vendor/phalcon/incubator/Library/Phalcon/Db/Adapter/Pdo/Oracle.php on line 68
#0 /srv/www/myapp/vendor/phalcon/incubator/Library/Phalcon/Db/Adapter/Pdo/Oracle.php(68): Phalcon\Db\Adapter\Pdo->connect(Array)
#1 [internal function]: Phalcon\Db\Adapter\Pdo\Oracle->connect(Array)
#2 /srv/www/myapp/common/library/Db/Adapter/Pdo/Oracle.php(26): Phalcon\Db\Adapter\Pdo->__construct(Array)
#3 /srv/www/myapp/services/services.php(546): Drywall\Db\Adapter\Pdo\Oracle->__construct(Array)
#4 [internal function]: Closure->Drywall\Platform\Services\{closure}()
#5 [internal function]: Phalcon\Di\Service->resolve(NULL, Object(Phalcon\Di\FactoryDefault))
#6 [internal function]: Phalcon\Di->get('db', NULL)
#7 [internal function]: Phalcon\Di->getShared('db')
...

@sergeyklay
Copy link
Contributor

@rlaffers Could you please provide script to reproduce?

@lightindigo
Copy link

@sergeyklay got exactly the same issue after trying to update from 2.0.13 to 3.2.2 (tried also 3.2.3, 3.1.x etc) both building and getting debian package from Packagecloud . The old way of setting default fetch mode (via passing options to Postgresql adapter constructructor as an example) is not working for some reason :(

Just the same error

Cannot use a scalar value as an array  in phalcon/mvc/model.zep on line 1139

The strange thing is that it was thrown while i was doing model->save();

It also seems that the behavior "test if there's a record and create if there none or update existing" not working as it did before :( We were just saving models previously on 2.0.13 without checking existence and it was OK, but now it just throws an error

@sergeyklay
Copy link
Contributor

@lightindigo Which database do you use?

@stale stale bot added the stale Stale issue - automatically closed label Apr 16, 2018
@Druid33
Copy link

Druid33 commented Apr 5, 2019

Hi, this bug is still active on phalcon 4.2.1

I found that:

  1. if database config has options key as last key, i got ErrorException: Cannot use a scalar value as an array
  2. if options config is not last key, i got RuntimeException: Trying to call method upper on a non-object. This is probably bug on line here:
    if typeof key == "string" && defined("\PDO::" . key->upper()) {

@sergeyklay
Copy link
Contributor

@Druid33 Could you please open a new issue

@cottton
Copy link
Contributor

cottton commented Aug 26, 2019

I did: #14330

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale Stale issue - automatically closed
Projects
None yet
Development

No branches or pull requests

6 participants