oracle765 Posted April 2, 2014 Share Posted April 2, 2014 /home/oracle765/public_html/loaddata.php which runs <?php ## Connect to a local database server (or die) ## $dbH = mysql_connect('****', '****', '****') or die('Could not connect to MySQL server.<br>' . mysql_error()); ## Select the database to insert to ## mysql_select_db('mydatabase') or die('Could not select database.<br>') . mysql_error(); ## CSV file to read in ## #mysql_query('DELETE FROM getpriceretailer'); #mysql_query('LOAD DATA LOCAL INFILE "/home/oracle765/public_html/feed/getprice.txt" INTO TABLE getpriceretailer FIELDS TERMINATED BY "\t" LINES TERMINATED BY "\n" (id,name,url,logo,rank,products,List);') or die('Error loading data file.<br>' . mysql_error()); ## Close database connection when finished ## mysql_close($dbH); ?> trouble is I just keep getting an email error saying /home/oracle765/public_html/loaddata.php: line 2: ?php: No such file or directory /home/oracle765/public_html/loaddata.php: line 5: syntax error near unexpected token `(' /home/oracle765/public_html/loaddata.php: line 5: `$dbH = mysql_connect('localhost', 'compareandchoose', 'Comparechoose12') or die('Could not connect to MySQL server.<br>' . mysql_error()); ' Any ideasI have a cron job Quote Link to comment Share on other sites More sharing options...
trq Posted April 2, 2014 Share Posted April 2, 2014 Best thread ever. Your not telling cron to use php to execute your script. Its trying to use Bash to execute it and that will never work. Having said that. Why are you even using php for this? It's a couple of simple sql queries. Quote Link to comment Share on other sites More sharing options...
oracle765 Posted April 2, 2014 Author Share Posted April 2, 2014 hi trq because I don't know any other way im new to php mysql Quote Link to comment Share on other sites More sharing options...
oracle765 Posted April 2, 2014 Author Share Posted April 2, 2014 #Get price retailers list /usr/bin/wget -O "/home/oracle765/public_html/feed/getprice.txt" 'http://www.getprice.com.au/affinityclick/ShopsList.aspx?Pass=****&ref=cc'; #mysql -u UNAME -p PASSWORD mysql.compareandchoose.com.au mydatabase -execute="LOAD DATA LOCAL INFILE '/home/oracle765/public_html/feed/getprice.txt' REPLACE INTO TABLE getpriceretailer FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\n' (id,name,url,logo,rank,products,List)" #mysql -u UNAME -p PASSWORD -h localhost mydatabase -e "LOAD DATA INFILE '/home/oracle765/public_html/feed/getprice.txt' REPLACE INTO TABLE getpriceretailer FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\n' (id,name,url,logo,rank,products,List)" I have commented them both out because the error message I get is mysql Ver 14.14 Distrib 5.5.32, for Linux (x86_64) using readline 5.1 Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Usage: mysql [OPTIONS] [database] -?, --help Display this help and exit. -I, --help Synonym for -? --auto-rehash Enable automatic rehashing. One doesn't need to use 'rehash' to get table and field completion, but startup and reconnecting may take a longer time. Disable with --disable-auto-rehash. (Defaults to on; use --skip-auto-rehash to disable.) -A, --no-auto-rehash and so onI have a script.sh file like so but that doesn't work either I just keep getting error saying Quote Link to comment Share on other sites More sharing options...
oracle765 Posted April 5, 2014 Author Share Posted April 5, 2014 any ideas anyone I just cant figure out whats missing and why its producing that error Quote Link to comment Share on other sites More sharing options...
boompa Posted April 5, 2014 Share Posted April 5, 2014 Try adding #!/usr/bin/env php as the very first line of loaddata.php and ensure that the loaddata.php file is executable. Quote Link to comment Share on other sites More sharing options...
oracle765 Posted April 5, 2014 Author Share Posted April 5, 2014 (edited) #!/bin/bash #Get price retailers list /usr/bin/wget -O "/home/oracle765/public_html/feed/getprice.txt" 'http://www.getprice.com.au/affinityclick/ShopsList.aspx?Pass=****&ref=cc'; mysql -u **** -p **** -h **** mydatabase -e "LOAD DATA LOCAL INFILE '/home/oracle765/public_html/feed/getprice.txt' REPLACE INTO TABLE getpriceretailer FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\n' IGNORE 1 LINES (id,name,url,logo,rank,products,List);" But it produces an error saying mysql: option '-e' requires an argument /home/oracle765/public_html/scripts/feedimport.sh: line 14: LOAD DATA LOCAL INFILE '/home/oracle765/public_html/feed/getprice.txt' REPLACE INTO TABLE getpriceretailer FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\n' IGNORE 1 LINES (id,name,url,logo,rank,products,List);: No such file or directoryive changed this now to a script.sh file will I still have to do that env thing? Edited April 11, 2014 by trq Quote Link to comment Share on other sites More sharing options...
trq Posted April 5, 2014 Share Posted April 5, 2014 No, its a bash script now not a php script. See the first line? Thats called a shebang and it tells your shell what interpreter to use to execute your script. Quote Link to comment Share on other sites More sharing options...
oracle765 Posted April 5, 2014 Author Share Posted April 5, 2014 Hi trq im totally lost lol this is new to me, when you said initially that the php would not work I changed it going off some tips on the net, but to be fair I have no to sure what I am doing now I gather the sh, bash way is the right approach is that right? thanks Quote Link to comment Share on other sites More sharing options...
trq Posted April 5, 2014 Share Posted April 5, 2014 Where did I say php wouldn't work? I didn't. I simply asked why you where using php when all you where doing was executing a couple of simple sql queries. Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted April 5, 2014 Share Posted April 5, 2014 Rather than dumping random codes into your post it would really help if you could actually explain what it is you are tying to do. Quote Link to comment Share on other sites More sharing options...
oracle765 Posted April 6, 2014 Author Share Posted April 6, 2014 ok sorry guys I am just getting a bit lost with this and yes trq your right apologies for the misreading anyway I have a feed and I am trying to auto load it into the MySQL db with a cronjob on a nightly basis The cron script manages to get the feed into the directory, logs onto mysql no problem but then produces the error as shown above. I think it may be the actual load statement some comma's or quotes or something. I just cant figure it out I have been on it for days. Quote Link to comment Share on other sites More sharing options...
trq Posted April 6, 2014 Share Posted April 6, 2014 A string cannot span multiple lines in bash (not as you have done anyway). Just put it all on one line. Quote Link to comment Share on other sites More sharing options...
oracle765 Posted April 6, 2014 Author Share Posted April 6, 2014 Usage: mysql [OPTIONS] [database] -?, --help Display this help and exit Default options are read from the following files in the given order: /etc/my.cnf /etc/mysql/my.cnf /usr/etc/my.cnf ~/.my.cnf The following groups are read: mysql client The following options may be given as the first argument: --print-defaults Print the program argument list and exit. --no-defaults Don't read default options from any option file. --defaults-file=# Only read default options from the given file #. --defaults-extra-file=# Read this file after the global files are read. a Variables (--variable-name=value) and boolean options {FALSE|TRUE} Value (after reading options) --------------------------------- ---------------------------------------- auto-rehash FALSE auto-vertical-output FALSE character-sets-dir (No default value) column-type-info FALSE comments FALSE compress FALSE debug-check FALSE debug-info FALSE database (No default value) default-character-set auto delimiter ; enable-cleartext-plugin FALSE vertical FALSE force FALSE named-commands FALSE ignore-spaces FALSE init-command (No default value) local-infile FALSE no-beep FALSE host localhost html FALSE xml FALSE line-numbers TRUE unbuffered FALSE column-names TRUE sigint-ignore FALSE port 0 prompt \d>\_ quick FALSE raw FALSE reconnect FALSE socket (No default value) ssl FALSE ssl-ca (No default value) ssl-capath (No default value) ssl-cert (No default value) ssl-cipher (No default value) ssl-key (No default value) ssl-verify-server-cert FALSE table FALSE user alan safe-updates FALSE i-am-a-dummy FALSE connect-timeout 0 max-allowed-packet 16777216 net-buffer-length 16384 select-limit 1000 max-join-size 1000000 secure-auth FALSE show-warnings FALSE plugin-dir (No default value) default-auth (No default value) ok I have put this all on one line and it shows the following output in my email but it still wont load Quote Link to comment Share on other sites More sharing options...
Solution oracle765 Posted April 8, 2014 Author Solution Share Posted April 8, 2014 any ideas anyone or is this totally the wrong way Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.