Importing Text File Into MySQL DB
I'm writing a script to import a text file with fields delimited by ~ into a MySQL DB. I'm trying to import everything into an array first, so that one array row = one record row. Here is some dummy data, with the 񟐚' record having a couple of new lines where a new paragraph is. Note the other records have NULL in the same field: PHP Code:
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Importing To DB From Pipe Delimited Text File
I am trying to make a PHP script that will import data from a pipe delimited text file in to a database. The problem I am having is that the fields have long descriptions in them and there are multiple line breaks for paragraphs. They contain HTML codes as well (<B>). The multiple line breaks are causing it to import the data strange, putting data in the wrong fields and totally missing some data as well. Here is what the text file Code:
Importing Excel File Into Mysql Database
I need help regarding importing excel file into mysql database.I am using PHP 5.0.2, mysql 4.2.13. I need code for importing excel file into mysql database and what will be the steps for it.
Importing A Flat Pipe Delimited File Into A MySQL Data Table
I have done this in perl but eeew I don't want to use perl anymore. I want to be able to take a flat file that looks like this: mbriones@...|Marian|Briones bobsmith@...|Bob|Smith janedoe@...|Jane|Doe (etc) The table has more than 3 fields, so I'd want to process the flat file and then do an INSERT into mailinglist SET field=$value for each line. Does someone have a nice way for me to do this? The flat file will be uploaded to the server via a form (copy) and then be processed.
CSV Importing To MySQL
Well I had the last script working perfectly. Except sometimes we rearrange the CSV "headers" so a field may be in one place on one file and another place on another file, yet they are the same thing. I've tired about 30 different scripts and none of them work at all. For example: Csv file looks like: work order,client name,start date,end date 7283728,"name,client",02/07/07,04/02/07 that is just the test file I've made up. I found out, the hard way, you cannot have spaces in your database fields. So what I am trying to do is take that first line, replace all spaces with an _. That away database fields can be like work_order and in the CSV file also. I tried using Code:
Importing Xml To Mysql
i am using this piece of code to import an xml file to mysql. $feed[$key] = $info; is causing the script to only return the last element of the xml file. I would like to return all elements but cant find a way to do so, <?php include 'library/config.php' include 'library/opendb.php' $file = "my-xml.xml"; $feed = array(); $key = ""; $info = ""; function startElement($xml_parser, $attrs ) { global $feed; } function endElement($xml_parser, $name) { global $feed, $info; $key = $name; $feed[$key] = $info; $info = ""; } function charData($xml_parser, $data ) { global $info; $info .= $data; } $xml_parser = xml_parser_create(); xml_set_element_handler($xml_parser, "startElement", "endElement"); xml_set_character_data_handler($xml_parser, "charData" ); $fp = fopen($file, "r"); while ($data = fread($fp, 8192)) !xml_parse($xml_parser, $data, feof($fp)); xml_parser_free($xml_parser); $sql= "INSERT INTO section ( "; $j=0; $i=count($feed); foreach( $feed as $assoc_index => $value ) { $j++; $sql.= strtolower($assoc_index); if($i>$j) $sql.= " , "; if($i<=$j) {$sql.= " ) VALUES ('";} } $h=0; foreach( $feed as $assoc_index => $value ) { $h++; $sql.= utf8_decode(trim(addslashes($value))); if($i-1>$h) $sql.= "', '"; if($i<=$h) $sql.= "','');"; } $query=trim($sql); echo $value; if (mysql_query($sql)){ echo "success in table creation."; } else { echo "no table created."; } echo mysql_error(); echo $sql; ?>
Importing Data Into Mysql
I'm starting working on a new project where I'll have to allow users to upload and import tab-formatted text files into the db. Should I use the LOAD DATA INFILE from PHP or write a custom procedure?
Duplicate Records In DB When Importing From CSV File
The code below is used to grab each row from a CSV file (except the first row) and insert it into a database, as long as it's not already in the DB. If I echo each row's data, it appears only once on the page. But, for some reason it inserts each row into the database 3 times. The code that echos the data, and the DB insertion code all appear within the same for loop. The database insertion code (below) works perfectly in another script. It's just copied/pasted into the for loop. $row = 0; $handle = fopen ("some-file.csv","r"); while ($data = fgetcsv ($handle, 1000, ",")) { if($row == 0){ // set the varible array $num = count ($data); $csvNames = array(); for ($c=0; $c < $num; $c++) { $csvNames[$c] = $data[$c]; eval("$" . $data[$c] . " = array();"); } $row = 1; }else{ $num = count ($data); $row++; for ($c=0; $c < $num; $c++) { $buildEval = "$" . $csvNames[$c] . " = "" . $data[$c] . "";"; eval($buildEval); echo $buildEval . "<br>"; // this properly displays only one row's data from the CSV file, then displays the next row in the CSV file when it loops again. // BUT FOR SOME REASON, THE DB CODE BELOW INSERTS EACH ROW FROM THE CSV FILE 3 TIMES. // Set variables with current date and time to be inserted into DB later $appDate = date('Y-m-d'); $appTime = date('H:i:s'); // Prepare the phone numbers for easy input into the database further down this page. $fHomePhoneCombined = $fHomePhone1 . "-" . $fHomePhone2 . "-" . $fHomePhone3; $fBusinessPhoneCombined = $fBusinessPhone1 . "-" . $fBusinessPhone2 . "-" . $fBusinessPhone3; // Connect to the database $db = mysql_connect ("localhost", "username", "password"); mysql_select_db ("mydatabase"); // Check to see if the record is new, $newRecord = 1; $queryNewRecord = mysql_query("SELECT * FROM cust_test WHERE first_name = '$fFirstName' AND last_name = '$fLastName' AND email = '$fEmail'"); if (mysql_num_rows($queryNewRecord) > 0){ $newRecord = 0; } // If it's NOT a new record, insert the contents into cust_test_bad DB // I'll insert this code later. It's not important for this test. // Write the information to the customers table, if it's a new record. if ($newRecord == 1){ $query = "INSERT INTO cust_test SET application_date = '$appDate', application_time = '$appTime', first_name = '$fFirstName', last_name = '$fLastName', email = '$fEmail', address = '$fAddress', state = '$fState', zip = '$fZip', home_phone = '$fHomePhoneCombined', best_time_to_call = '$fBestTime', lead_buyer = '$lbuy'"; $result = mysql_query($query) or die('Failed because: '.mysql_error()); } } // end of for ($c=0; $c < $num; $c++) } } fclose ($handle);
Importing Excel Into A MySQL Database
i have an excel file I want to read into a database. I found a tutorial which says to save the file into a xml file, then it basically gets all the data out, and puts it into an array Code:
Importing Data To MySql From Web Page
I'm using Drupal(a CMS), along with MySQL and PHP to import data into a database. I'm trying to import a bunch of sentences on one page into the database, but each in their own row. For example: News ----- Brand new site New employee hired New work acquired Basically, I need to know how to pull those into the database as one row each, instead of pulling all three elements into the database in the same row. They're all stored in a $content tag, b/c I wrote the page in PHP. So, any ideas on how to make it, so I can insert the $content into the database, but at a line break, I need to insert a new row?
Importing To Mysql Without LOAD DATA LOCAL
I've just gone through the learning curve of realizing most virtual hosts have "LOAD DATA LOCAL" disabled :( I have a two meg delimited ascii file I need to import on a regular basis (26 fields) Anyone have a nice import routine using fopen they are willing to share before I attempt to hack one out myself? I can't seem to find such an animal out there (though some are close). Such a shame, from what I have read, load data is much faster...
Importing A Field From MySQL Into A Variable In Flash?
I have a query that is giving me the field that I require from my database using PHP. What is the best way to import this variable into flash? Can I echo the number out on the page and have Flash import it that way? Could I use the Load Variable command? code:
Importing Large Amounts Of Data Via File Upload
I was wondering how anyone here deals with move large amounts of mysql data to be uploaded to the server? Large as in 75MB CSV file. I have a client who wants to admin there database with 15,000 users. They manage all data offline and want to upload to the site for display purposes only. My server has 5MB php file upload limit. I really do not want to up this limit. What I am wondering is how does cPanel or PHP MyAdmin get around this upload limit using php scripting?
Export Mysql To Text File Via PHP
I need help on how to export one of table mysql to text file to download. (not saving text into server) something with like header("Content-type: text/plain");
Reading From Text File And Storing In MySQL
I have a text file consist of 10 digit phone numbers one number per line like this: 5553332244 5553332244 5553332244 5553332244 etc… How do I read a text file line by line and populate the data into an array to store it into a MySQL database? My database is below:
Read The Contents Of A Text File Into MySql Using PHP
New to this, have the basics, can build a form and such. My problem is I need to be able to open a file on a pc/s on the network, read the data character by character, check to see if a certain character is present, if it is, update the database and continue reading the file until it comes across the character again, updates the database and so on . . . .
Book Script ,should I Use Txt File Or Mysql Text Field ?
I am doing simply book script, where we will have hundred of books,user will be able to read chapter by chapter or search etc.. As u know that book contain will have html tages..etc.. and each book is around 200 kB....My php script read text file and display. It's a huge text file. I am thinking to use database instead of text file. But text files are very huge. My question, should i use database instead of text file ? which one is faster and better. I have noticed, when i copy 150 kB files and paste into phpmyadin, it gives me internel error..but it insert record. I used txt field for book contain.
Uploading Info From A Text File Into A MySQL Database
what would the PHP and SQL code be to say basically: make a new row and put this in the field, what comes after each comma goes in a new field, and each new line should be a new row. I have a huge text file that i don't have a way to upload directly into a MySQL database because my webhost isn't allowing it for some reason.
Using Php To Move Rows From Text File Into Mysql Table
Can anyone point me in the right direction for the way to read a text file a line at a time and separate the fields on that line and use them as data in an INSERT to add a record to a mysql table. Then read the second line in text file and repeat.
Site Stats, Php/mysql OR Flat Text File?
I'm have a cms and I want site stats built in, thus apache's stats or cpanel etc don't cut it for multiple users. I have a working stat query below, the problem is, in a short time 12 hours, it's grown to 109k with 500 records. now I'm not adding a row for every person, I create a session, and if they already have a row, I update clicks (page clicks) as you can see. still, it's big, the bots are eating it, so I figure, why not just create a separate table for bots, with 1 row per day and a click count. there, smaller. but with multiple users, and lots of normal hits, this will still grow quite large very fast! so I'm wondering if flat text files would be a better solution? but perhaps opening and writing to a text file constantly gets very slow? I'm confused. Code:
MYSQL Query Script To Reading From A Text File
Im having a hard time converting the following tree menu script to read nodes from a text file, rather then a database. This script works perfectly and is exactly what i am looking for, however it relies on query's from a MySQL database (I don't know how to set one up is the real problem). I would like to keep the feature where you can pass a parameter through the script and its expands the corresponding folder. Code:
Quickly Adding Text To A Mysql Text Field That Is NOT Empty
Is there a way to insert text into a mysql text field that already has text into it; without having first to extract the existing data and append the new text to that string variable and then insert the new string. Basically i'm looking for a way to do it with a single query not 2 (one being a select to gather existing data).
Gaining Access To How MySql Parses Text For Full Text
I want to gain access to the function or process MySql uses to parse words and phrases for Full Text searching. Here is an example. If the user inputs... Milan in history MySql will search for milan, history, and milan history. Is there a way to extract just the combination of terms MySql uses to search the db without the stop words? Stop words are automatically eliminated from the search request unless the user encloses a phrase in quotes. What I am trying to do is develop a script to highlight found search terms and phrases. I can explode a phrase into single words but if I do that the stop words would be included in the array. If there is some way of getting into the parsed words or phrases MySql Full Text actually uses to search, I can use each of those combinations as a keyword in my highlighting script. This request is about searching for the code or any code related to the questions involved.
Read And Display Japanese Text From Text File
I posted a question regarding reading japanese text from a text file. Well, since I solved the problem, I thought I'd post my solution for the benefit of other people with the same problem. The plan was to make a script to read and display japanese text. I will use it for making a japanese proverb script and for a japanese language study script. Method : I wrote a simple kanji text file (saved with UTF-8 encoding) I wrote a simple PHP script to display the file contents (saved with UTF-8 encoding) I specified the content-type header for the HTML page : <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> *** All files have the same encoding. *** UTF-8 supports japanese characters. and it works! this is my PHP (and HTML) script : <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>PHP : Japanese Text File Read : Exercise 1</title> </head> <body> <?php $filename="japanese.txt"; //open file $fp = fopen($filename,'r'); //loop through each line in the file while($line=fgets($fp)) { //output current text file line print $line."<br>"; } //close file handle fclose($fp); ?> </body> </html> I know it's a very simple script, for testing purposes only. It displays the contents of the japanese text file line by line. The key was to save all files in the same encoding (I used UTF-8) and to specify the encoding / charset in the HTML header (<meta http-equiv="Content-Type" content="text/html; charset=utf-8">)
Remove Text Header In Text File
I have been having trouble removeing two header lines at the top of my txt file. You will see in my code the different things I have tried but with no luck. Below I posted my script and data. I am doing a few other things in my script as you will notice but this is the only thing I am having troble with. Code:
Importing PDF Or EPS
Does anyone know of a way to import an existing PDF or EPS for editing without the commercial PDI library?
Importing Data
I have this file cvs that's roughly 2.5 meg. Right now, it uses a function like this to import the data into the table. PHP Code:
Importing Pages
I've written a content management system that I'm now selling to my customers. It's very nice when we have a blank canvas of a site, but a pain in the arse when there is already a site in place. What I'm in the process of *trying* to put together is a script that would do the following: A simple form where you put the address of the site with the static pages The script then spiders through the site, takes everything between <body> and </body> and chucks the rest away It would then take out all class definitions and all embedded styles like font tags etc but leaves tables, <p> <H?> etc This would leave a very plain page of HTML that would be inserted into a database. CSS would control the fonts etc. I'm aware that there would need to be some tidying up if there was any javascript or anything and also some basic formatting. What I want to know is 1. Has it been done and, if so, where might I find something like this 2. Might it have any commercial value to other developers? Regarding 2, I'm thinking how much time something like this might save me if I have to convert anything more than a few pages of static HTML into something that I can put in a database.
Importing SQL Files
is it possile to import data from a sql file which has been exported from another database without using something like phpmyadmin ? Or must it be done using phpmyadmin. Also is it possible to just export data without having to use phpmyadmin or similar?
Import_request_variables Isn't Importing My Changes To My Globals
The server I'm running my PHP on has "magic_quotes" turned on, so all the input I get (from GET, POST, and cookies) is escaped with backslashes. I don't want this (I handle my own escaping, and I need to be able to work with unescaped strings), but I'm not allowed to change the setting on the server, so I need to figure out a way to "undo" magic quotes. This code itself works... function stripslashes_array($v) { return is_array($v) ? array_map('stripslashes_array', $v) : stripslashes($v); } if (get_magic_quotes_gpc()) { foreach (array('POST', 'GET', 'REQUEST', 'COOKIE') as $gpc) $GLOBALS["_$gpc"] = array_map('stripslashes_array', $GLOBALS["_$gpc"]); } But my problem is that I then want to use import_request_variables to bring any form data into the global variable space, and that's not reflecting the changes I just made to the globals... in other words, if after that code I say: $foo = "GLOBALS["_GET"]["test"]; import_request_variables("gp", "in_"); $bar = $in_test; and I submit the page with "test" set to a'b'c, then $foo will be a'b'c while $bar will be a'b'c. How do I get the stripslashed values into my global variables without having to stripslash each one individually?
Importing With PhpMyAdmin Error.
I've been testing import csv files with PHP. Well it's going ok, I guess, when you save with Excel everything works fine. The output .csv file is from another piece of software, and it appears to be completely fine. Look at this: Line [1] from Excel saved CSV under "date" is this. 59:04.0 Line [1] from Software saved CSV under "date" is this. 2007-06-14 11:59:04.0 Excel takes out most of the date/time. When it is almost taken out it imports with PhpMyAdmin just fine. Well I need that date. For some reason when that date/time is complete MySQL kicks it back. Know the weird thing, I can go into PhpMyAdmin and insert just "2007-06-14 11:59:04.0" into the "date" column. So, this completely makes no sence why MySql is kicking it back. When I compare both csv files they are exactly alike, except the date; yet, there is no problem...anyone have any idea how to fix this? Or maybe a loop around it using PHP. I've got a class file that imports the Excel CSV just fine.
Using COM Objects Or Importing To Outlook
I've been asked to look at developing a web-based system for tracking forms. In itself, it is fairly simple. However, one item they want to look at is Outlook integration for tasks. We use an internal exchange server and I have read about being able to use COM objects to write tasks for Outlook from PHP. However, I'm having difficulty with this part. The script I do have is timing out and documentation on using COM objects is fairly sparse. Should I be looking at something other than PHP? Code:
Importing Form Data To Ms Access
Does anyone know if one can import a web form data into ms access db? Does the ms access db have to be on the same server as the web form?
Encoding Error When Importing With Simple XML
When importing XML with SimpleXML -php5-with accents they come with errors... I guest this is an encoding thing... example: when importing this frase in spanish "La Tecnología más avanzada" I get: La TecnologÃÂa más avanzada if the original text was in utf-8 or in iso-8859-1 how do I can get them correctly according to it encoding?
Importing Items From Online Calendar To Mail Client
Has anyone any idea if it's possible to import items from a database table into your mail client calendar? I'm using Ximian Evolution, but Outlook is very relevant to, because most users are still stuck in the M$ mess...
Text Box To .txt File
does anyone know how to make a text box in php that when submitted, it writes to a .txt file?
PHP/MySQL Text And SEO
I'm creating a news script to store news articles in a MySQL database and using PHP to access this DB. I was wondering since PHP processes before the page is loaded will it display the text from the DB and allow this text to be picked up by search engines?
Text File Display
I have a number of SQL reports that create standard 132 column text files. The user wishes to view these files in a browser in addition to their daily printing on a laser printer. I can handle directory structure, etc with PHP but I would like to know what is the best way of displaying these text files on screen. We can select them but they are very plain. Is there a TXT2HTML ot TXT2XML type tool that can display headings, bolding, etc without too much difficulty. I would rather not reprogram the reports as there are hundreds of them, and embedding HTML would not be an answer as they need to be printed on a regular laser.
Saving To A Text File.
I haven't been able to find a way to save the results of a MYsql query into a tab delimited text file... Anyone know how to do this, or if there are any already written scripts out there that perform this, or a similar function?
Database Row To Text File
I need to get the contents of a MySQL database field into a text file, and write the file to the server. I can not seem to get any filesystem functions to work, because it tells me I do not have permission to do anything. I am on virtual hosting, so it seems easier for me to try to FTP files to my own server. Perhaps you guys can give me some pointers, this is kind of the idea I am running on:
Writing To A Text File
i have a text file with the number 250 in it and nothing else. i have a variable which is worth a 300. How can i add this value to the one in the file so that the value of the file has changed to 550?
Text File Into Variable
I'm setting up an script that will send mail to an address given by a user. The problem is that the body of the e-mail varies depending on a few responses that the person gives, and writing out like 1000 lines of code just to get each of the outcomes covered is not my idea of fun. My question is, is there any way to make a variable in PHP the contents of a .txt file so I don't have to have that big of a script?
Retrieval From A Text File
How would I go about retrieving info from a text file into a variable field? If the data is stored in more than one line or separated by line breaks?
|