Jump to content

something wrong with my php code i think


Go to solution Solved by oracle765,

Recommended Posts

/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 ideas
I have a cron job
#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 on



I have a script.sh file like so but that doesn't work either I just keep getting error saying
#!/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 directory




ive changed this now to a script.sh file will I still have to do that env thing? Edited by trq

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

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.

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

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.