wordygo/application/controllers/util.php
2013-11-26 12:54:17 +01:00

40 lines
1.2 KiB
PHP

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Util extends CI_Controller {
public function __construct() {
parent::__construct();
}
public function run() {
for($i = 65; $i <= 67; $i++) {
echo '<br />' . $i . '<br />';
$sql = 'SELECT * FROM en_definitions LIMIT ?,10000';
$params = array($i * 10000);
$query = $this->db->query($sql, $params);
$result = $query->result_array();
foreach($result as $r) {
$id = $r['id'];
$def = $r['definition'];
preg_match_all('/\[\[.+?\]\]/', $def, $matches);
foreach($matches[0] as $m) {
$sql = 'SELECT * FROM en_words WHERE name=?';
$params = array(trim($m, '[]'));
$query = $this->db->query($sql, $params);
$result = $query->row_array();
if(isset($result['id'])) {
$sql = 'INSERT IGNORE INTO en_synonyms (definition_id, word_id) VALUES(?,?)';
$params = array($id, $result['id']);
try {
$query = $this->db->query($sql, $params);
echo $this->db->affected_rows() > 0 ? ' Worked ' : ' Did not work ';
} catch(Exception $e) {
echo '<br /> ERROR. Defintion: ' . $id . ' Word: ' . $result['id'] . '<br />';
}
}
}
echo ' ROW ';
}
}
echo '<br /><br />END!!!! YAY!!!';
}
}
?>