Author |
Message |
sting
Involved


Joined: Sep 23, 2003
Posts: 456
Location: Somewhere out there...
|
Posted:
Thu Jun 29, 2006 6:25 pm |
|
Anyone had any experience or know how to pull data from a dbase iv export (.dbf) into MySql via PHP?
The files 'appear' tab delimited, but upon further review (and opening through Excel) it is clear that they are not.
I can pull them into Excel and Access with no problem (and from there get them to MySql) but need a way to automate this through PHP if possible.
I know of the dbase_open and associated utilities, but have never used them against straight flat export files and definitely not through Nuke - any ideas as to how I would go about successfully calling this function from within a php-nuke module? Its not in the nuke includes, so am curious as to how that is done.
Thanks in advance...
-sting, who once again feels 'n00bish'. |
_________________ You see - I told you I wasn't paranoid. They were really out to get me. |
|
 |
 |
gregexp
The Mouse Is Extension Of Arm

Joined: Feb 21, 2006
Posts: 1497
Location: In front of a screen....HELP! lol
|
Posted:
Thu Jun 29, 2006 6:33 pm |
|
have you attempted fopen?
like this:
$fp = fopen ("yourfile.ext", "r");
$bytes = "10000000000";
$buffer = fread($fp, $bytes);
fclose ($fp);
$buffer1 = "$buffer";
$query = "";
if ($p_transaction_safe) {
$buffer2 = 'START TRANSACTION;' . $buffer1 . '; COMMIT;';
};
$query_split = preg_split ("/[;]+/", $buffer2);
foreach ($query_split as $command_line) {
$command_line = trim($command_line);
if ($command_line != '') {
$query_result = mysql_query($command_line);
if ($query_result == 0) {
echo "$buffer";
};
};
};
return $query_result; |
_________________ For those who stand shall NEVER fall and those who fall shall RISE once more!! |
|
 |
 |
sting

|
Posted:
Thu Jun 29, 2006 6:52 pm |
|
Can't say that I have - I am familiar with direct file reads, but haven't tried it on this as the format was dbase iv - can you explain some of it?
For example:
Quote: |
preg_split ("/[;]+/", $buffer2);
|
How is this representative of DbaseIV data vs any other type of data?
(Sorry, code newb on this one...)
-sting |
|
|
|
 |
sting

|
Posted:
Thu Jun 29, 2006 8:52 pm |
|
Just read this on the php.net pages -
Quote: | In order to enable the bundled dbase library and to use these functions, you must compile PHP with the --enable-dbase option. |
Anyone know of a way to determine whether or not my ISP is using that option? (Without asking them of course). . .
-sting |
|
|
|
 |
gregexp

|
Posted:
Thu Jun 29, 2006 9:18 pm |
|
ok
this is what this does, if ur file works on phpmyadmin, as is, content wise, then this script, that line in particular breaks it all down into sql commands, since mysql_query can only run one command at a time
this buffers as many commands(seperated by the semi-colin) into a variable, then applys each line as a SINGLE sql command until it is finished running all the info it has buffered and since the buffer variable is feined as the contents on a file, it breaks the contents down to one command per ;
so now instead of it running mysql_query ("1;2;3;4;5;6;7;8;9;0;");
which will not run
This will run
mysql_query("1");
mysql_query("2");
mysql_query("3");
mysql_query("4");
etc
phpinfo() should allow u to find out.
but it wouldnt run nuke if it was disabled(i believe) |
|
|
|
 |
sting

|
Posted:
Thu Jun 29, 2006 9:30 pm |
|
You know I haven't tried reading it directly from phpMyAdmin - let me play with that and see what happens.
Thanks for the idea(s)
-sting |
|
|
|
 |
sting

|
Posted:
Thu Jun 29, 2006 9:33 pm |
|
Nope, its as I expected - doesn't read it in at all.. gets hung up on the tabs and the format from the dbf export.
I can open these things all day long in Excel and in Access, which I could then export to a MySql query, but I much prefer the idea of loading it directly from the php source.
Thanks so far for the brainstorming...
-sting |
|
|
|
 |
Raven
Site Admin/Owner

Joined: Aug 27, 2002
Posts: 17088
|
Posted:
Fri Jun 30, 2006 12:03 am |
|
sting wrote: | Just read this on the php.net pages -
Quote: | In order to enable the bundled dbase library and to use these functions, you must compile PHP with the --enable-dbase option. |
Anyone know of a way to determine whether or not my ISP is using that option? (Without asking them of course). . .
-sting |
Run phpinfo(); |
|
|
|
 |
montego
Site Admin

Joined: Aug 29, 2004
Posts: 9457
Location: Arizona
|
Posted:
Wed Jul 05, 2006 5:44 pm |
|
sting, do mind posting a few lines of the .dbf file here? |
_________________ Only registered users can see links on this board! Get registered or login!
Only registered users can see links on this board! Get registered or login! |
|
|
 |
|