davideairaghi / php

repository of php code
Apache License 2.0
12 stars 9 forks source link

Cannot use a scalar value as an array #2

Open ruudboon opened 8 years ago

ruudboon commented 8 years ago

When trying to load a model with Model::findFirst(id); I get the following notice. Notice: Cannot use a scalar value as an array in phalcon/db/result/pdo.zep on line 219 in script on line x

It also happens when using find like the phalcon example

// Bind parameters
$parameters = array(
    "name" => "Robotina",
    "year" => 2008
);

// Casting Types
$types = array(
    "name" => Column::BIND_PARAM_STR,
    "year" => Column::BIND_PARAM_INT
);

// Query robots binding parameters with string placeholders
$robots = Robots::find(
    array(
        "name = :name: AND year = :year:",
        "bind"      => $parameters,
        "bindTypes" => $types
    )
);

And result in the model not loaded.

davideairaghi commented 8 years ago

have you tried something like:

$parameters = array( "conditions"=>"name=?0 AND year=?1", "bind"=>array("Robotina",2008) ); $robots = Robots::find($parameters);

ruudboon commented 8 years ago

I tried but it's giving the same errors. It looks like it's triggered by numRows() function in phalcon/db/result/pdo.zep that it's fireing a new query the get the number of rows. https://github.com/phalcon/cphalcon/blob/master/phalcon/db/adapter/pdo.zep

davideairaghi commented 8 years ago

I tried to reproduce the problem on my installation, but without success. Have you tried to make a test using another type of database (ie: mysql) ?

ruudboon commented 8 years ago

Yeah I did. Works fine with a different DB. I will see if I can isolate the issue.

davideairaghi commented 8 years ago

In file Airaghi/PhalconPHP/MSSQL/Dialect/Mssql.php uncomment lines 432 and 433, so you will be able to see the "real queries" sent to the database.

Which version of PhalconPHP are you using ?

davideairaghi commented 8 years ago

have you tried to use the "native" odbc driver for SQL Server released by Microsoft?

just to be sure it's not a problem related to FreeDTS

ruudboon commented 8 years ago

I'm on FreeBSD the Microsoft drivers aren't available for FreeBSD :(

hamster1979 commented 6 years ago

$parameters = array( "conditions"=>"name=?0 AND year=?1", "bind"=>array("Robotina",2008) ); $robots = Robots::find($parameters); - this work fine, but string placeholders not working ((((

davideairaghi commented 6 years ago

i really never tested "string placeholders", the project using these classes doesn't use them. This implementation is just a "basic one", so it has some limitation ...