PHP code example of victorwesterlund / innodb-fk

1. Go to this page and download the library: Download victorwesterlund/innodb-fk library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

victorwesterlund / innodb-fk example snippets


use victorwesterlund\ForeignKeys

use victorwesterlund\ForeignKeys

$fk = new ForeignKeys($host, $user, $pass, ForeignKeys::DATABASE_NAME);

$fk->for("test", "bar")->get_constraints();

[
   // Name of the column that has a foreign key reference
   "fk" => [
      // key is the database and table it references. Value is the column
      "test.foo" => "id"
   ]
]

$rows = [
   [
      "id" => 1,
      "fk" => 2
   ],
   [
      "id" => 2,
      "fk" => 1
   ]
];

$rows = $fk->for("test", "bar")->resolve_all($rows);

// $rows will become
[
   [
      "id" => 1,
      "fk" => [
         "id"    => 2,
         "value" => "lorem ipsum dolor sit amet"
      ]
   ],
   [
      "id" => 2,
      "fk" => [
         "id"    => 1,
         "value" => "consectetur adipiscing elit"
      ]
   ]
]