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
×
×
  • 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.