Jump to content


  • Posts

  • Joined

  • Last visited

Everything posted by ludo1960

  1. 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. Sorry, the link is here https://www.php.net/manual/en/set.mongodb.php there is our chum MongDB\Driver\Manager .
  3. Hi there, Thats the old driver, i'm using the new one here: https://www.php.net/manual/en/set.mongodb.php
  4. 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.
  5. 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. only because I sorted the table by item, here it is sorted by id:
  7. 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: ''. 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
  8. I have no idea what you mean by general log
  9. 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??
  10. 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.
  11. 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>";
  12. 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.
  13. 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?
  14. 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>";
  15. Yes, USE mydb; ---->then SELECT COUNT(*) FROM apidata;
  16. 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?
  17. foreach ($myarray as $k => $v) { $newarr[strval($k)] = $v['href']; } Does not work??
  18. From the mysql shell, i'm runnig: SELECT COUNT(*) FROM apidata;
  19. 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 ??
  20. oops posted in wrong place, sorrry!
  21. 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();
  22. Gonna read up on error reporting, and try and find out why the double entry is haappening, many thanks, for all the help!
  23. 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?
  24. I am using PHPmyadmin, but have also tried from the mysql shell and the results tally
  25. HTML displays correctly as does php echo
  • Create New...

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.