Jump to content

ludo1960

Members
  • Content Count

    123
  • Joined

  • Last visited

Everything posted by ludo1960

  1. ludo1960

    PHP Mongodb driver connection and insert

    Thanks for advice, wasn't getting anywhere till I found this https://www.php.net/manual/en/mongodb.tutorial.library.php now it works a treat, Once installed, you have access to all the mongo goodies https://docs.mongodb.com/php-library/current/ MongoDB\Client was indeed correct! Thanks again!
  2. Hello guys, I've installed the mongoDB PHP driver using "sudo pecl install mongodb" Testing shows driver is installed correctly and it appears nicely in phpinfo(): ludo@aegir:~$ php7.2 -i | grep -i mongodb mongodb MongoDB support => enabled MongoDB extension version => 1.5.3 MongoDB extension stability => stable mongodb.debug => no value => no value For connecting I've got: $db = new MongoDB\Driver\Manager("mongodb://localhost:27017"); Now I want to define a collection and insert a record, i've been using code from here https://www.php.net/manual/en/set.mongodb.php: $collection = $db->mydatabase->mytable; $result = $collection->insertOne( [ 'name' => 'test', 'item' => 'testitem' ] ); But this fails Notice: Undefined property: MongoDB\Driver\Manager::$mydatabase in /var/www.... Has anyone got a workingg example of defining and inserting into mongoDB. Seems the driver was updated fairly recently and so stuff on the internet is not always relevant.
  3. ludo1960

    PHP Mongodb driver connection and insert

    Sorry, the link is here https://www.php.net/manual/en/set.mongodb.php there is our chum MongDB\Driver\Manager .
  4. ludo1960

    PHP Mongodb driver connection and insert

    Hi there, Thats the old driver, i'm using the new one here: https://www.php.net/manual/en/set.mongodb.php
  5. ludo1960

    Insert data into mysql

    Good news guys, found the error: I was having a tough time trying to install xdebug, I used the output from php -v and put it in here: https://xdebug.org/wizard.php The output from my php.ini was PHP 7.2.18-..... Then the wizard gave me the steps to follow. The script needs phpize from the php-dev bundle seemingly. As I had just rebuilt my dev box, I was watching the xdebug install doing its thing and I noticed that php7.0 and php7.3 kept whizzing by as the script progressed. Strange I thought, i've got php7.2 why is xdebug downloading all this stuff?? Needless to say when i tried to get xdebug working by adding zend_extension=/usr/lib/php/20170718/xdebug.so to the php.ini, and you guessed it, it didn't work! Plan B was called for, re-installed my dev box from scratch. Then installed php7.2-dev so that I had the right version of phpize, and it all went to plan. No more double entries in the database, and all errors are displayed...Result!!! Moral of the tale, dont trust the xdebug wizard!
  6. ludo1960

    Insert data into mysql

    Hi guys, I have an array: array ( [apple]=> red, [orange] => orange, [banana] => yellow ) That I want to insert into the apidata table, the PDO connection is good so I guess my code is wrong: $mykeys = implode(', ', array_keys($newarr)); $myplaceholders[] = '(' . implode (", ", array_fill(0, count($newarr), '?')) . ')'; $values = array_values($newarr); $res = $db->prepare("INSERT INTO apidata (item, value) VALUES $myplaceholders") ; $res->execute([$mykeys, $values]); The apidata table has three fields id (auto_increment) item and value, where am I going wrong? Thanks
  7. ludo1960

    Insert data into mysql

    only because I sorted the table by item, here it is sorted by id:
  8. ludo1960

    Insert data into mysql

    Ok, after trying it all again ie truncate, load page again, still double entries. Here's the maria.err log 2019-05-14 20:37:23 139840968318336 [Note] InnoDB: innodb_empty_free_list_algorithm has been changed to legacy because of small buffe$ 2019-05-14 20:37:23 139840968318336 [Note] InnoDB: Using mutexes to ref count buffer pool pages 2019-05-14 20:37:23 139840968318336 [Note] InnoDB: The InnoDB memory heap is disabled 2019-05-14 20:37:23 139840968318336 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins 2019-05-14 20:37:23 139840968318336 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier 2019-05-14 20:37:23 139840968318336 [Note] InnoDB: Compressed tables use zlib 1.2.8 2019-05-14 20:37:23 139840968318336 [Note] InnoDB: Using Linux native AIO 2019-05-14 20:37:23 139840968318336 [Note] InnoDB: Using SSE crc32 instructions 2019-05-14 20:37:23 139840968318336 [Note] InnoDB: Initializing buffer pool, size = 128.0M 2019-05-14 20:37:23 139840968318336 [Note] InnoDB: Completed initialization of buffer pool 2019-05-14 20:37:23 139840968318336 [Note] InnoDB: Highest supported file format is Barracuda. 2019-05-14 20:37:24 139840968318336 [Note] InnoDB: 128 rollback segment(s) are active. 2019-05-14 20:37:24 139840968318336 [Note] InnoDB: Waiting for purge to start 2019-05-14 20:37:24 139840968318336 [Note] InnoDB: Percona XtraDB (http://www.percona.com) 5.6.42-84.2 started; log sequence number $ 2019-05-14 20:37:24 139840301561600 [Note] InnoDB: Dumping buffer pool(s) not yet started 2019-05-14 20:37:24 139840968318336 [Note] Plugin 'FEEDBACK' is disabled. 2019-05-14 20:37:24 139840968318336 [Note] Server socket created on IP: '127.0.0.1'. 2019-05-14 20:37:24 139840968318336 [Note] Reading of all Master_info entries succeded 2019-05-14 20:37:24 139840968318336 [Note] Added new Master_info '' to hash table 2019-05-14 20:37:24 139840968318336 [Note] /usr/sbin/mysqld: ready for connections. Version: '10.1.38-MariaDB-0+deb9u1' socket: '/var/run/mysqld/mysqld.sock' port: 3306 Debian 9.8
  9. ludo1960

    Insert data into mysql

    I have no idea what you mean by general log
  10. ludo1960

    Insert data into mysql

    ok, I added !include /etc/mysql/mariadb.cnf to my /etc/mysql/my.cnf and added log_error=/var/log/mysql/mariadb.err to /etc/mysql/mariadb.cnf restarted mysql, truncated and tried again, still double entry and no mariadb.err where it should be??
  11. ludo1960

    Insert data into mysql

    Added it to /etc/php/7.2/cli/php.ini : error_reporting = E_ALL error_reporting(E_ALL); ini_set('display_errors', '1'); Restarted Nginx, sudo service php7.2-fpm reload, truncated the database table, tried page again, still double entry and no errors.
  12. ludo1960

    Insert data into mysql

    sure, here you go: <?php error_reporting(E_ALL); ini_set('display_errors', '1'); include_once 'connection.php' ; $url = "http://admin.contenta.com/api"; //$url = 'https://live-contentacms.pantheonsite.io/api'; $jsondata = file_get_contents($url); $response = json_decode($jsondata, true); $myarray = $response['links'] ; foreach ($myarray as $k => $v) { $newarr[strval($k)] = $v['href']; } $res = $db->prepare("INSERT INTO apidata (item, value) VALUES (?, ?)") ; foreach ($newarr as $key => $value) { $res->execute( [ $key, $value ] ); } echo "<pre>"; print_r( $newarr ); echo "</pre>";
  13. ludo1960

    Insert data into mysql

    Just tried it: error_reporting(E_ALL); ini_set('display_errors', '1'); Still no errors reported, double entries persist. I think a re-install of my dev box is on the cards.
  14. ludo1960

    Insert data into mysql

    Stranger and stranger, if I run the code with the original code above: i get: Array ( [self] => h [blocks] => h [comments] => h [reviews] => h [commentTypes] => h [consumer--consumer] => h [files] => h [graphql_query_map--graphql_query_map] => h [imageStyles] => h [mediaBundles] => h [images] => h [articles] => h [pages] => h [recipes] => h [node--tutorial] => h [contentTypes] => h [menus] => h [vocabularies] => h [categories] => h [tags] => h [roles] => h [users] => h [menuLinks] => h ) And the database is like so: Then changing to your new version of the code gives me: Array ( [self] => https://live-contentacms.pantheonsite.io/api [blocks] => https://live-contentacms.pantheonsite.io/api/blocks [comments] => https://live-contentacms.pantheonsite.io/api/comments [reviews] => https://live-contentacms.pantheonsite.io/api/reviews [commentTypes] => https://live-contentacms.pantheonsite.io/api/commentTypes [consumer--consumer] => https://live-contentacms.pantheonsite.io/api/consumer/consumer [files] => https://live-contentacms.pantheonsite.io/api/files [graphql_query_map--graphql_query_map] => https://live-contentacms.pantheonsite.io/api/graphql_query_map/graphql_query_map [imageStyles] => https://live-contentacms.pantheonsite.io/api/imageStyles [mediaBundles] => https://live-contentacms.pantheonsite.io/api/mediaBundles [images] => https://live-contentacms.pantheonsite.io/api/images [articles] => https://live-contentacms.pantheonsite.io/api/articles [pages] => https://live-contentacms.pantheonsite.io/api/pages [recipes] => https://live-contentacms.pantheonsite.io/api/recipes [node--tutorial] => https://live-contentacms.pantheonsite.io/api/node/tutorial [contentTypes] => https://live-contentacms.pantheonsite.io/api/contentTypes [menus] => https://live-contentacms.pantheonsite.io/api/menus [vocabularies] => https://live-contentacms.pantheonsite.io/api/vocabularies [categories] => https://live-contentacms.pantheonsite.io/api/categories [tags] => https://live-contentacms.pantheonsite.io/api/tags [roles] => https://live-contentacms.pantheonsite.io/api/roles [users] => https://live-contentacms.pantheonsite.io/api/users [menuLinks] => https://live-contentacms.pantheonsite.io/api/menuLinks ) And my database looks like: My database must be goosed! How lucky is that?
  15. ludo1960

    Insert data into mysql

    Try this yourself and you will see double entries: <?php include_once 'connection.php' ; //$url = "http://admin.contenta.com/api"; $url = 'https://live-contentacms.pantheonsite.io/api'; $jsondata = file_get_contents($url); $response = json_decode($jsondata, true); $myarray = $response['links'] ; foreach ($myarray as $k => $v) { $newarr[strval($k)] = $v['href']; } $res = $db->prepare("INSERT INTO apidata (item, value) VALUES (?, ?)") ; foreach ($newarr as $key => $value) { $res->execute( [ $key, $value ] ); } echo "<pre>"; print_r( $newarr ); echo "</pre>";
  16. ludo1960

    Insert data into mysql

    Yes, USE mydb; ---->then SELECT COUNT(*) FROM apidata;
  17. ludo1960

    Insert data into mysql

    And here was me thinking I found the error, back to the drawing board! Oh, and I added error_reporting(E_ALL); to the page, but still no errors show?
  18. ludo1960

    Insert data into mysql

    foreach ($myarray as $k => $v) { $newarr[strval($k)] = $v['href']; } Does not work??
  19. ludo1960

    Insert data into mysql

    From the mysql shell, i'm runnig: SELECT COUNT(*) FROM apidata;
  20. ludo1960

    Insert data into mysql

    Reading https://www.php.net/manual/en/language.types.array.php the $newarr array at the moment is [article] => somevalue, should be ['article'] => somevalue so, foreach ($myarray as $k => $v) { $newarr[$k] = $v['href']; } // how to cast $newarr key to string ??
  21. ludo1960

    Transform array

    Hi guys, if I have an array like so: Array ( [articles] => Array ( [href] => http://admin.contenta.com/api/articles ) [blocks] => Array ( [href] => http://admin.contenta.com/api/blocks ) [categories] => Array ( [href] => http://admin.contenta.com/api/categories ) ..... } How can I transform it to assoiative array ie 'articles' => 'http://admin.contenta.com/api/articles' etc? Thanks
  22. ludo1960

    Transform array

    oops posted in wrong place, sorrry!
  23. ludo1960

    Insert data into mysql

    Already got that in my connection.php, and no errors are shown? function pdoConnect() { $dsn = "mysql:dbname=".DBNAME."; host=".HOST."; charset=utf8"; $db = new pdo($dsn, USERNAME, PASSWORD, [ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, ]); return $db; } $db = pdoConnect();
  24. ludo1960

    Insert data into mysql

    Gonna read up on error reporting, and try and find out why the double entry is haappening, many thanks, for all the help!
  25. ludo1960

    Insert data into mysql

    I changed the item column to be UNIQUE, and now 23 records are inserted. Don't thinks it is a proper fix, would love to know why the code causes a double insert. I don't see how the code is being run twice, surely a web page just refreshes itself once?
×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.