Jump to content

ludo1960

Members
  • Posts

    123
  • Joined

  • Last visited

Everything posted by ludo1960

  1. Adding the function and the counts so: echo recordCount($db) . '<br>'; foreach ($newarr as $item => $val) { $res->execute( [ $item, $val ] ); } echo recordCount($db) . '<br>'; gives me 0 23 but still get the data doubled up, beginning to think i've got a bum copy of mariaDB version 10.1.38
  2. Just tried delete and create a new table, still inserted twice!
  3. db truncated each time before I vist the page, and yep, no HTML
  4. As requested the complete test.php: <?php include 'connection.php' ; $url = "http://admin.contenta.com/api"; $jsondata = file_get_contents($url); $response = json_decode($jsondata, true); $myarray = $response['links'] ; foreach ($myarray as $k => $v) { $newarr[$k] = $v['href']; } $res = $db->prepare("INSERT INTO apidata (item, value) VALUES (?,?)") ; foreach ($newarr as $item => $val) { $res->execute( [ $item, $val ] ); } echo "<pre>"; print_r( $newarr ); echo "</pre>"; // here are the 23 itemss returned Then I just visit in the browser http://mytestsite.com/test.php
  5. $newarr has 23 items, data base has been truncated, 46 items are inserted. I've put the code on a php page and visited it in the brower, could that cause the doubling up? Or is there a command that says "i've finished inserting data, close the query"? Clutching at straws now The connection.php from yourself: <?php const HOST = 'localhost'; const USERNAME = 'xxxxxxxxxxxxxxxxxxx'; const PASSWORD = 'xxxxxxxxxxxxxxxxxxx'; const DBNAME = "xxxxxxxxxxxxxxxxxxx"; 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();
  6. A lot neater, thats'for sure, alas the data is still doubled up. $res = $db->prepare("INSERT INTO apidata (item, value) VALUES (?,?)") ; foreach ($newarr as $item => $val) { $res->execute( [ $item, $val ] ); }
  7. Nearly there, data is inserted twice: $keys = array_keys( $newarr ); $vals = array_values( $newarr ); $size = sizeof( $newarr ); $res = $db->prepare("INSERT INTO apidata (item, value) VALUES (?, ?)") ; for($x = 0; $x < $size; $x++ ) { $res->execute([ $keys[$x], $vals[$x] ]); another hint please
  8. can I put a foreach round the $res->execute() ?
  9. 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
  10. Silly typo at my end, apologies: foreach ($myarray as $k => $v) { $new[$k] = $v['href']; } echo "<pre>", print_r($new), "</pre>"; gives me : Array ( [articles] => http://admin.contenta.com/api/articles [blocks] => http://admin.contenta.com/api/blocks [categories] => http://admin.contenta.com/api/categories ......... perfect as usual Barand, thanks!
  11. Using foreach ($myarray as $k => $v) { $new[$k] = $v['href']; } gives me : 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 to change: [articles] => Array ( [href] => http://admin.contenta.com/api/articles ) to [articles] => http://admin.contenta.com/api/articles
  12. Not sure what the right words are, but an array like so: Array ( 'articles' => 'http://admin.contenta.com/api/articles' , 'blocks' => 'http://admin.contenta.com/api/blocks', 'categories' => 'http://admin.contenta.com/api/categories ........ )
  13. 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
  14. Hi guys, I am getting data from a json source: ``` $jsondata = file_get_contents($url); $response = json_decode($jsondata, true) echo "<pre>"; print_r(array_keys($response));; echo "</pre>"; ``` and this returns: ``` Array ( [0] => jsonapi [1] => data [2] => links ) ``` I want to extract data from specific key in the data array (eg 'title'): ``` [data] => Array ( [0] => Array ( [type] => recipes [id] => d6cd7643-6e44-4d26-9ed9-9da7196cef12 [attributes] => Array ( [internalId] => 7 [isPublished] => 1 [title] => Deep mediterranean quiche [createdAt] => 2019-05-07T13:34:27+0200 [updatedAt] => 2019-05-07T13:34:27+0200 [isPromoted] => 1 [path] => /recipes/deep-mediterranean-quiche [cookingTime] => 30 [difficulty] => medium [ingredients] => Array ( [0] => For the pastry: [1] => 280g plain flour [2] => 140g butter [3] => Cold water [4] => For the filling: [5] => 1 onion [6] => 2 garlic cloves [7] => Half a courgette [8] => 450ml soya milk [9] => 500g grated parmesan [10] => 2 eggs [11] => 200g sun dried tomatoes [12] => 100g feta ) [numberOfservings] => 8 [preparationTime] => 40 [instructions] => ``` How do I loop through the data array and select just the 'title' and 'difficulty' for example?
  15. After much fiddling around I see that the make test command seems to want to use php 7.3, but php -v returns ``` ludo@aegir:/usr/lib/php$ php -v Failed loading /usr/lib/php/20180731/xdebug.so: /usr/lib/php/20180731/xdebug.so: undefined symbol: zend_hash_add PHP 7.2.18-1+0~20190503103213.21+stretch~1.gbp101320 (cli) (built: May 3 2019 10:32:13) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.2.18-1+0~20190503103213.21+stretch~1.gbp101320, Copyright (c) 1999-2018, by Zend Technologies ``` How can I make xdebug use php 7.2, I did use php 7.2 in the xdebug configuration tool ``` ludo@aegir:~/Downloads/xdebug-2.7.2$ make test Build complete. Don't forget to run 'make test'. ===================================================================== PHP : /usr/bin/php7.3 PHP_SAPI : cli PHP_VERSION : 7.3.5-1+0~20190503093827.38+stretch~1.gbp60a41b ZEND_VERSION: 3.3.5 PHP_OS : Linux - Linux aegir.local.com 4.9.0-9-amd64 #1 SMP Debian 4.9.168-1 (2019-04-12) x86_64 INI actual : /home/ludo/Downloads/xdebug-2.7.2/tmp-php.ini More .INIs : CWD : /home/ludo/Downloads/xdebug-2.7.2 Extra dirs : VALGRIND : Not used ===================================================================== TIME START 2019-05-09 02:47:18 ===================================================================== No tests were run. ``` Any ideas guys?
  16. Hi gizmola, I have nginx and php-fpm, php -i does not show xdebug as being installed. I added ``` zend_extension = /usr/lib/php/20180731/xdebug.so ``` to the bottom of /etc/php/7.2/fpm/php.ini and restarted nginx AFAIK i don't have a xdebug.ini.
  17. Hi Guys, On a fresh debian 9 install, php7.2 all working nicely. Then I try to install xdebug. I followed the instructions here https://xdebug.org/docs/install Basically I ran ``` sudo pecl install xdebug ``` and added zend_extension=/usr/lib/php/20180731/xdebug.so to my /etc/php/7.2/fpm/php.ini file I've checked in /usr/lib/php/20180731 and xdebug.so is there. When i view my phpinfo() there is no mention of xdebug, pretty sure that aint right. How to go about checking my installation
  18. Don't be shy guys, have a go: sudo apt install --reinstall mongodb and now when I try mongo: ludo@aegir:~$ mongo MongoDB shell version: 3.2.11 connecting to: test 2019-04-24T16:57:13.004+0100 I NETWORK [thread1] recv(): message len 1347703880 is invalid. Min 16 Max: 48000000 2019-04-24T16:57:13.004+0100 E QUERY [thread1] Error: network error while attempting to run command 'isMaster' on host '127.0.0.1:27017' : connect@src/mongo/shell/mongo.js:229:14 @(connect):1:6 exception: connect failed How can I get rid of that pesky NETWORK [thread] recv(): message len1347703880 ?
  19. Hi guys, I'm hoping a network specialist chances upon my post. I've had mongodb up and running on localhost for months and all of a sudden, it stops connecting. This is what I tried: ludo@aegir:~$ mongod 2019-04-24T08:44:45.933+0100 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none' 2019-04-24T08:44:46.082+0100 I CONTROL [initandlisten] MongoDB starting : pid=2419 port=27017 dbpath=/data/db 64-bit host=aegir.local.com 2019-04-24T08:44:46.082+0100 I CONTROL [initandlisten] db version v4.0.9 2019-04-24T08:44:46.082+0100 I CONTROL [initandlisten] git version: fc525e2d9b0e4bceff5c2201457e564362909765 2019-04-24T08:44:46.082+0100 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.1.1b 26 Feb 2019 2019-04-24T08:44:46.082+0100 I CONTROL [initandlisten] allocator: tcmalloc 2019-04-24T08:44:46.082+0100 I CONTROL [initandlisten] modules: none 2019-04-24T08:44:46.083+0100 I CONTROL [initandlisten] build environment: 2019-04-24T08:44:46.083+0100 I CONTROL [initandlisten] distmod: debian92 2019-04-24T08:44:46.083+0100 I CONTROL [initandlisten] distarch: x86_64 2019-04-24T08:44:46.083+0100 I CONTROL [initandlisten] target_arch: x86_64 2019-04-24T08:44:46.083+0100 I CONTROL [initandlisten] options: {} 2019-04-24T08:44:46.099+0100 E STORAGE [initandlisten] Failed to set up listener: SocketException: Address already in use 2019-04-24T08:44:46.122+0100 I CONTROL [initandlisten] now exiting 2019-04-24T08:44:46.122+0100 I CONTROL [initandlisten] shutting down with code:48 ludo@aegir:~$ So from there i tried: root@aegir:/home/ludo# lsof -iTCP -sTCP:LISTEN -n -P COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME mysqld 676 mysql 17u IPv4 20517 0t0 TCP 127.0.0.1:3306 (LISTEN) postgres 677 postgres 3u IPv6 17243 0t0 TCP [::1]:5432 (LISTEN) postgres 677 postgres 6u IPv4 17244 0t0 TCP 127.0.0.1:5432 (LISTEN) nginx 683 root 10u IPv4 17233 0t0 TCP *:80 (LISTEN) nginx 683 root 11u IPv4 17234 0t0 TCP *:27017 (LISTEN) nginx 683 root 12u IPv6 17235 0t0 TCP *:80 (LISTEN) nginx 683 root 13u IPv4 17236 0t0 TCP *:8000 (LISTEN) nginx 684 www-data 10u IPv4 17233 0t0 TCP *:80 (LISTEN) nginx 684 www-data 11u IPv4 17234 0t0 TCP *:27017 (LISTEN) nginx 684 www-data 12u IPv6 17235 0t0 TCP *:80 (LISTEN) nginx 684 www-data 13u IPv4 17236 0t0 TCP *:8000 (LISTEN) master 1016 root 13u IPv4 18422 0t0 TCP 127.0.0.1:25 (LISTEN) master 1016 root 14u IPv6 18423 0t0 TCP [::1]:25 (LISTEN) miniserv. 1089 root 5u IPv4 16225 0t0 TCP *:10000 (LISTEN) miniserv. 1089 root 6u IPv6 16226 0t0 TCP *:10000 (LISTEN) root@aegir:/home/ludo# so then I : kill 683 then when I try sudo mongod the connection is made. here are the last few lines of my mongodb log ludo@aegir:/etc/nginx/sites-available$ sudo tail -n 25 /var/log/mongodb/mongod.log Apr 24 09:00:59 aegir NetworkManager[485]: <info> [1556092859.1543] dhcp4 (ens33): gateway 192.168.52.2 Apr 24 09:00:59 aegir NetworkManager[485]: <info> [1556092859.1544] dhcp4 (ens33): server identifier 192.168.52.254 Apr 24 09:00:59 aegir NetworkManager[485]: <info> [1556092859.1545] dhcp4 (ens33): lease time 1800 Apr 24 09:00:59 aegir NetworkManager[485]: <info> [1556092859.1547] dhcp4 (ens33): nameserver '192.168.52.2' Apr 24 09:00:59 aegir dbus[463]: [system] Activating via systemd: service name='org.freedesktop.nm_dispatcher' unit='dbus-org.freedesktop.nm-dispatcher.service' Apr 24 09:00:59 aegir NetworkManager[485]: <info> [1556092859.1548] dhcp4 (ens33): domain name 'localdomain' Apr 24 09:00:59 aegir NetworkManager[485]: <info> [1556092859.1549] dhcp4 (ens33): wins '192.168.52.2' Apr 24 09:00:59 aegir NetworkManager[485]: <info> [1556092859.1550] dhcp4 (ens33): state changed bound -> bound Apr 24 09:00:59 aegir systemd[1]: Starting Network Manager Script Dispatcher Service... Apr 24 09:00:59 aegir dhclient[679]: bound to 192.168.52.186 -- renewal in 730 seconds. Apr 24 09:00:59 aegir dbus[463]: [system] Successfully activated service 'org.freedesktop.nm_dispatcher' Apr 24 09:00:59 aegir systemd[1]: Started Network Manager Script Dispatcher Service. Apr 24 09:00:59 aegir nm-dispatcher: req:1 'dhcp4-change' [ens33]: new request (1 scripts) Apr 24 09:00:59 aegir nm-dispatcher: req:1 'dhcp4-change' [ens33]: start running ordered scripts... Apr 24 09:01:01 aegir CRON[3570]: pam_unix(cron:session): session opened for user aegir by (uid=0) Apr 24 09:01:01 aegir CRON[3571]: (aegir) CMD (/usr/bin/env php /usr/local/bin/drush '@hostmaster' hosting-dispatch ) Apr 24 09:01:04 aegir php: DIGEST-MD5 common mech free Apr 24 09:01:04 aegir CRON[3570]: pam_unix(cron:session): session closed for user aegir Apr 24 09:01:38 aegir sudo: pam_unix(sudo:session): session closed for user root Apr 24 09:02:01 aegir CRON[3597]: pam_unix(cron:session): session opened for user aegir by (uid=0) Apr 24 09:02:01 aegir CRON[3598]: (aegir) CMD (/usr/bin/env php /usr/local/bin/drush '@hostmaster' hosting-dispatch ) Apr 24 09:02:05 aegir php: DIGEST-MD5 common mech free Apr 24 09:02:05 aegir CRON[3597]: pam_unix(cron:session): session closed for user aegir Apr 24 09:02:24 aegir sudo: ludo : TTY=pts/1 ; PWD=/etc/nginx/sites-available ; USER=root ; COMMAND=/usr/bin/tail -n 25 /var/log/mongodb/mongod.log Apr 24 09:02:24 aegir sudo: pam_unix(sudo:session): session opened for user root by (uid=0) can anybody suggest what's going wrong here? PS after a reboot I'm right back to square one.
×
×
  • 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.