SQL column type issue
Posted: Thu Apr 12, 2012 5:35 am
I'm retrieving tweets from a rss feed page; the code i use works but when i inserted it into the database i found this - The guid valued retrieve from the document is an 18 character integer value so i set the type of the column to int(28). As soon as i started running the code the value in that column wasn't the 18 character integer but this value 2147483647. After some changes i decided to change the type of the column to varchar(18) and it solved the problem. Is this an sql issue?
I tested the data received from the feed and when i printed it the 18 character integers were displayed; the code i use
I tested the data received from the feed and when i printed it the 18 character integers were displayed; the code i use
Code: Select all
<?php
$handle = @file_get_contents('http://twitter.com/statuses/user_timeline/user_.rss');
if ($handle != false) {
//
$xml = new SimpleXMLElement($handle);
// connection to database
$total = count($xml->channel->item) - 1;
$updated = 0;
$notUpdated = 0;
for ($i=0; $i<= $total; $i++) {
//
preg_match('/\d{18,}/', $xml->channel->item[$i]->guid, $match);
//
$guid = mysqli_real_escape_string($sqli, $match[0]);
$description = mysqli_real_escape_string($sqli, $xml->channel->item[$i]->description);
$pubDate = mysqli_real_escape_string($sqli, $xml->channel->item[$i]->pubDate);
//
$qry = "SELECT COUNT(`id`) FROM `twitter_tbl` WHERE `guid` = '" . $guid . "' ";
$sql = mysqli_query($sqli, $qry);
$ary = mysqli_fetch_array($sql);
$rows = $ary[0];
//
if ($rows == 0) {
$qry = "INSERT INTO `twitter_tbl` (`description`, `pubdate`, `guid`)
VALUES ('" . $description . "', '" . $pubDate . "', '" . $guid . "')";
$sql = mysqli_query($sqli, $qry);
}
}
}
?>