I've been trying to insert data from a "newline" deliminated file using fgets().(Tried other methods also) Still after insert , Weird numbers are inserted into the DB . The file is based on a linux host , as is the database. DB is the default latin_swedish.... Can anyone Please enlighten me as to what is going on ??
Hello, Please can you post the code in question, and some sample data so we can have a crack at it. Jay
Here you go Jay --- Data written into File (limited amount) :- 6774715430909970394 11828365781198180384 1756115755140636583 12400341346200954451 Code ;- $fp = fopen("filehavingthedata.php","r") or die("error opening file"); $contact = fgets($fp); while(!feof($fp)) { $q = "INSERT INTO thetable VALUES ($contact)"; mysql_query($q, $this->connection) or die("Could not Insert $contact"); $contact = fgets($fp); } fclose($fp); PHP:
6774715430909970394 11828365781198180384 1756115755140636583 12400341346200954451 and many numbers are present in the .php file..... Does it matter if it is .php or .txt ?
You might need to match your SQL Statement $q = "INSERT INTO thetable (field) VALUES ($contact)"; PHP: Jay
Use shell_exec command to directly upload data from files to database . Example usage $db = mysql_connect("$dbhost","$dbusername","$dbpasswd") or die ("Couldn't connect to server."); mysql_select_db("$database_name", $connection) or die("Couldn't select database."); $TheFile = "SQL.txt"; $User = "$dbusername"; $Password = "$dbpasswd"; $DatabaseName = "$database_name"; $Results = shell_exec( "mysql -u$User -p$Password -hlocalhost $DatabaseName < $TheFile" ) or die ("Error"); echo "Results from MySQL import of $DatabaseName with User $User with file $TheFile:\r\n $Results\r\n"; PHP:
@ jithosh.js Jitosh , I'm on a shared server .... And dont think I'm allowed Shell Access @Kaizoku It's not Blob . It is 'bigint' with max length 30 @jayshah Tried it earlier ... no avail @all Thank you for replying . I do appretiate you helping me out . The Data inserted into the DB is twice , sometimes thrice or any random number of times .... and it is insert serially (although garbage) like 123123123,124356354,13456456,14456456,2334534543,25567568756 ,268567567 and on and on ...... Still havent found the solution , Anyone there who can figure this out ??
Does it matter if I store the line deliminated data in a .php(server process it as a php script) or in a .txt file ?? Will try that out now .....
Sorry Guys .. .my Bad ... The Data(numbers) were being inserted after being being sorted out (automatically , dont know how !!) .. .and being inserted in a serial manner ..... I was looking for the same order as those in the file (not an ordered manner !!) .... Thank you all <<<< RESOLVED >>>