Coder Social home page Coder Social logo

Comments (7)

BenMorel avatar BenMorel commented on July 21, 2024

Hi, are you passing an array of values? queue() expects the values directly:

$inserter->queue(7, 'DDWWWB', NULL, ...);

and not:

$inserter->queue([7, 'DDWWWB', NULL, ...]);

from db.

cborchmann avatar cborchmann commented on July 21, 2024

Hi, my var_dump echos this:

string(117) "7,'4B1616',NULL,'SWR1310',51.764226,12.048035,36975,-64,42,406,'2019-04-29','2019-04-29 10:17:01.900000',1556525821.9"

The manual version is:

$inserter->queue(7,'4B1616',NULL,'SWR1310',51.764226,12.048035,36975,-64,42,406,'2019-04-29','2019-04-29 10:17:01.900000',1556525821.9); which works fine...

from db.

BenMorel avatar BenMorel commented on July 21, 2024

In the first case you're passing the arguments as a string, which is obviously a single argument.
Where is your data coming from?

from db.

cborchmann avatar cborchmann commented on July 21, 2024

Hi, i´m prasing an JSON String.

from db.

BenMorel avatar BenMorel commented on July 21, 2024

Please share the code!

from db.

cborchmann avatar cborchmann commented on July 21, 2024

Hello Ben,

my approach to build a $ values variable was not necessary at all. I realized that I can simply feed the values into the function.

Here is my working code example:

$inserter = new BulkInserter($pdo, 'flights_tmp', ['source', 'hex', 'squawk', 'callsign', 'altitude']);

  foreach ($row_outer[$x] as $row) {
            
        // hex: the 24-bit ICAO identifier of the aircraft, as 6 hex digits.
        // The identifier may start with '~', this means that the address is a non-ICAO address (e.g. from TIS-B).
        if(isset($row['hex'])) {
            $hex = strtoupper(trim($row['hex']));
        }else $hex = NULL;

        // squawk: the 4-digit squawk (octal representation)
        if(isset($row['squawk'])) {
            $squawk = intval($row['squawk']);
        }else $squawk = NULL;

        // flight: the flight name / callsign
        if(isset($row['flight'])) {
            $flight = strtoupper(trim($row['flight']));
        }else $flight = '?';

        // lat, lon: the aircraft position in decimal degrees
        if(isset($row['lat'])) {
            $latitude = floatval($row['lat']);
        }else $latitude = NULL;

        // lat, lon: the aircraft position in decimal degrees
        if(isset($row['lon'])) {
            $longitude = floatval($row['lon']);
        }else $longitude = NULL;

          $inserter->queue($source, $hex, $squawk, $squawk, $flight, $altitude);

      }

      $inserter->flush();

from db.

BenMorel avatar BenMorel commented on July 21, 2024

Hi, exactly. If you're passing an array, it's considered a single argument hence the argument count does not match. Alternatively, you can unpack an array this way:

$values = [$source, $hex, $squawk, $squawk, $flight, $altitude];

$inserter->queue(...$values); // unpacking the array into multiple arguments

from db.

Related Issues (5)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.