MySQL Forums
Forum List  »  Full-Text Search

Re: Oracle 8i to mySQL full text search issues.
Posted by: Nick Roper
Date: July 24, 2004 05:00AM

Keith,

You can try this. I haven't had time to do full error handling - but it should give you a start! This could be developed into an interface that displays the url and first part of the text for existing items in the table with options to view the web page, update or delete items etc.

Let me know if it works OK.

Nick

<?php

/*

File: urlgrabber.php
Author: Nick Roper, Logical Elements
Date: 24/07/04
Usage: May be copied and used on the understanding that
Nick Roper or Logical Elements accept no liability for
any errors or loss of data that may occur. The user is reponsible
for making any changes necessary for use in their own
environment.
Requires: MySQL, PHP and web-server

Notes: Displays a text field for entry of a URL
On clicking the Go button the URL will be opened
stored in a variable and then processed with the
addslashes function to escape special characters
before inserting into a MySQL database.

MySQL: This script uses a MySQL table 'test and table 'url_library'
created as follws:

CREATE TABLE `url_library` (
`url_id` int(8) unsigned NOT NULL auto_increment,
`url_url` varchar(50) default NULL,
`url_html` text,
PRIMARY KEY (`url_id`)
) TYPE=MyISAM

The code should be edited to specify values for the following:

$hostname
$database
$username
$password
*/

$doit = false;
$msg = 'Enter URL and press Go...';

$go = isset($_POST['submit']);

if ($go) {
$url = $_POST['urltoget'];
$doit = (!$url=='');
}

if (!$doit) {
$msg = 'Please enter a URL to get';
}
else {
if (getURLText($url)){
$insert = insertURL($url, $url_html);
$msg = ($insert) ? 'URL inserted into database' : 'Failed to insert URL';
}
}

?>

<html>
<head>
<title>URL Grabber</title>
</head>

<body>

<form method="post" action ='<?php echo $_SERVER['PHP_SELF']; ?>'>

URL: &nbsp;
<input type='text' size=50 name='urltoget'>
<input type="submit" name="submit" value="Go"><br>
<?php echo $msg; ?>

</form>


</body>
</html>

<?php

function getURLText($url){

global $url_html;

$size = 1048576;
if ($url_text = fopen($url, 'r')){
$url_html = fread($url_text, $size);
$url_html = addslashes($url_html);
$okread = true;
}

return $okread;

}

function insertURL($url, $url_html){

$hostname = 'localhost';
$database = 'my_database';

$username = 'my_user';
$password = 'my_password';
$connection = mysql_pconnect($hostname, $username, $password) or die(mysql_error());

mysql_select_db($database, $connection);

$insert_sql = "insert into url_library (url_url, url_html)
values ('$url', '$url_html')";

return ($insert_res = mysql_query($insert_sql, $connection));

}

?>

--
Nick Roper

Options: ReplyQuote


Subject
Views
Written By
Posted
Re: Oracle 8i to mySQL full text search issues.
6466
July 24, 2004 05:00AM
3958
September 08, 2004 05:46AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.