-
LOAD DATA LOCAL INFILE WHERE clause?
I've just noticed a problem that I think someone could help me with. Basically what I've got is: $var = "celebrity"; $line = str_replace("'", "\'", $line); $line[9] = strtolower($line[9]); if (strpos($line[9], $var)){ But I've noticed that if celebrity is the first word on a line, then it's not included. Why's that?! [EDIT]: I've just used all my wisdom and changed it to this which seems to work: $var = "celebrity"; $line = str_replace("'", "\'", $line); $line[9] = strtolower($line[9]); if (strpos($line[9], $var) !== FALSE){ I know it's working, but is that the correct way of doing it? Could someone explain why? Also, in the examples below, which would be correct? if (strpos($line[20], $var1) !== FALSE || strpos($line[20], $var2) !== FALSE){ Or this one: if (strpos($line[20], $var1) || strpos($line[20], $var2) !== FALSE){ I'm thinking it's probably the first of the two?
-
LOAD DATA LOCAL INFILE WHERE clause?
I had a feeling that might be the case, just wanted to double check!
-
-
LOAD DATA LOCAL INFILE WHERE clause?
1 more question! When I'm in phpMyAdmin and displaying all the rows, I've noticed that it will say something like: Showing rows 0 - 109 (110 total, Query took 0.0692 sec) But where is the 110th row? Why does it always seem to be 1 short?!
-
-
LOAD DATA LOCAL INFILE WHERE clause?
Thanks for all the help! It's been much appreciated! I'll definitely look into PDO at a later date. Just glad to get this working for now. Can I just ask, where did you learn this stuff? Did you study it in Uni or just pick it up yourself? What sort of qualifications are available for this kind of thing?
-
-
LOAD DATA LOCAL INFILE WHERE clause?
I've pretty much got this working now I think! I've done it differently though, instead of using PDO I've just used the usual MySQL connect. What's the difference here? Does it really matter? I'm also having a small problem with apostrophe's ( ' ) within the CSV file conflicting on input. Much appreciated for all the help with this though! It turned out to be a lot more complicated than I had thought, It's not something I could of done entirely on my own, not until I understand a bit more about PHP.
-
LOAD DATA LOCAL INFILE WHERE clause?
Not really! I've basically used this code to display the output in the browser, it was just to get me started: $file = fopen('CSV/newfile.csv', 'r'); while (($line = fgetcsv($file)) !== FALSE) { //$line is an array of the csv elements $var1 = "name"; $var2 = "address"; $line[20] = strtolower($line[20]); if (strpos($line[20], $var1) || strpos($line[20], $var2)) { echo '<pre>'; print_r($line[0]); echo "<br />"; print_r($line[7]); echo '<br />'; print_r($line[4]); echo '<br />'; print_r($line[14]); echo '<br />'; print_r($line[36]); echo '<br />'; print_r($line[39]); echo '</pre>'; } } fclose($file); Everything displays how I want it to in the browser. But I don't really know where to go from here to insert each line into the right columns of my database. I tried the first bit of code, using PDO but I don't understand the $connectionString part. From what I read on Google it should be like: $pdo = new PDO('mysql:host=localhost;dbname=mydbname', 'myusername', 'mypassword');
-
-
-
-
LOAD DATA LOCAL INFILE WHERE clause?
That helps a lot, but how would I include another variable? Something like: $var1 = "Find this"; $var2 = "Find that"; Or $var = "Find this" or "Find that" ; So that I could get a result if either of them are in the string? Also is there a way to make the variable so that it isn't case sensitive?
-
LOAD DATA LOCAL INFILE WHERE clause?
It's been a long process for a beginner but I'm definitely getting somewhere though! Can someone tell me if I can use wildcards like this? if ($line[20] == '%xyz%' I can get it to print the line if I use the exact phrase, but is there anyway I could just use part of the phrase inside of 2 of those, like '%xyz%'.
-
-
LOAD DATA LOCAL INFILE WHERE clause?
Wow thanks! There's plenty here to get me going in the right direction! Much appreciated guys! I'm going to check it all out properly tonight!
-
LOAD DATA LOCAL INFILE WHERE clause?
Ok so I basically turn each row of my CSV file into an array using the code above and then have to insert each requested row that into the database using PDO?
-
-
LOAD DATA LOCAL INFILE WHERE clause?
Could anyone give me some help with this? I've literally sat and scratched my head all day trying to work it out! I came across the following code: $csv = explode("\n", file_get_contents('test.csv')); foreach ($csv as $key => $line) { $csv[$key] = str_getcsv($line); } Which I believe turns my CSV file into an array? But then how do I go about using it to delete specific rows where their not like "xyz" and then convert it back into a CSV file for uploading to database?!
-
-
-
LOAD DATA LOCAL INFILE WHERE clause?
Is that the only way it can be done?
-
LOAD DATA LOCAL INFILE WHERE clause?
126 views and no replies tells me this can't be done then! Haha. What about using PHP to remove rows from the CSV file or extracting the rows I need and putting them into another CSV file before loading them into MySQL. Would that be possible?
-
LOAD DATA LOCAL INFILE WHERE clause?
Is this possible? I've basically got a cronjob script that inputs data from a CSV file into my database. Everything works fine except one of my CSV files has a lot of data that I don't need. I don't want to import all of it as it's just taking up resources. Is it possible to use something like this: "LOAD DATA LOCAL INFILE 'CSV/Filename.csv' INTO TABLE `TABLE 3` WHERE `colu` LIKE '%xyz%' FIELDS TERMINATED BY ',' ENCLOSED BY '\"' ESCAPED BY '\\\' IGNORE 1 LINES (name, date);" `colu` being column U in the CSV file?
-
PHP Login Cron Job
Thanks man! That's done the job perfectly! I would never of been able to get that right and was having no luck with Google either! Very much appreciated!