Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    Regular Coder ttttt's Avatar
    Join Date
    Oct 2005
    Posts
    372
    Thanks
    0
    Thanked 0 Times in 0 Posts

    PHP4, XML and CSV

    Hi,
    I'm looking to use XML files instead of MySQL, but I'm running php4.
    I have been searching google all afternoon, and can't find anything that helps. I was wondering if anyone has a decent tutorial on ?SAX? or something else. I do NOT however want to install anything from PEAR and I won't be persuaded to use MySQL.
    If what I ask of is not possible, can I use CSV?
    Thanks,
    ttttt
    http://openoffice.org/- Microsoft Office without the Microsoft.
    [home page][forum]
    Versatile, free software

  • #2
    $object->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Jun 2003
    Posts
    3,092
    Thanks
    2
    Thanked 23 Times in 23 Posts
    What kind of problem are you trying to solve, or what specific kind of application are you trying to write? It would help if we had a littlel more information on what you're trying to do.
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    SNAP to it!

  • #3
    Regular Coder ttttt's Avatar
    Join Date
    Oct 2005
    Posts
    372
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well, I'm trying to use this database to power my website which will act along the lines of a content management system. I would like to use XML instead of MySQL because of various reasons and I have no idea of how to use php4 and xml relationships.
    Thanks for the reply,
    ttttt
    http://openoffice.org/- Microsoft Office without the Microsoft.
    [home page][forum]
    Versatile, free software

  • #4
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,073
    Thanks
    11
    Thanked 98 Times in 96 Posts
    XML files are a poor substitute for a database because of the overhead of parsing them (PERL is much faster at munging text files), if the site is only small then perhaps its workable , php4 still has built in expat xml functions allowing you to write your own parsers, and if you search this forum there is a reference somewhere to simpleXML classes for php4

    If I had to use a flatfile database I would use csv and/or serialized PHP arrays, SQLite would be worth a look but I think its an extesion in PHP4?
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #5
    Regular Coder ttttt's Avatar
    Join Date
    Oct 2005
    Posts
    372
    Thanks
    0
    Thanked 0 Times in 0 Posts
    So how would I use csv and serialized arrays?
    ttttt
    http://openoffice.org/- Microsoft Office without the Microsoft.
    [home page][forum]
    Versatile, free software

  • #6
    $object->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Jun 2003
    Posts
    3,092
    Thanks
    2
    Thanked 23 Times in 23 Posts
    Here's an example of code that reads a CSV file and extracts each item into the appropriate variable for processing.

    Code:
    $handle = fopen("file.csv", 'r');
    while(($data = fgetcsv($handle, 1000, ",")) !== false)
    {
    	list($col1, $col2, ...) = $data;
    }
    fclose($handle);
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    SNAP to it!

  • #7
    Regular Coder ttttt's Avatar
    Join Date
    Oct 2005
    Posts
    372
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for that!
    And how exactly would I write the csv file? I've never used csv before, except for transferring email contacts.
    ttttt
    http://openoffice.org/- Microsoft Office without the Microsoft.
    [home page][forum]
    Versatile, free software

  • #8
    $object->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Jun 2003
    Posts
    3,092
    Thanks
    2
    Thanked 23 Times in 23 Posts
    Code:
    $handle = fopen($filename, "w");
    fwrite($handle, $csv_code);
    fclose($handle);
    where $filename = whatever file you want to write the data to

    $csv_code = PHP code to write out comma separated values data
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    SNAP to it!

  • #9
    Regular Coder ttttt's Avatar
    Join Date
    Oct 2005
    Posts
    372
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by vinyl-junkie View Post
    Code:
    $handle = fopen($filename, "w");
    fwrite($handle, $csv_code);
    fclose($handle);
    where $filename = whatever file you want to write the data to

    $csv_code = PHP code to write out comma separated values data
    I think I must not have been clear enough.
    I meant by hand not using php.
    Could you please explain how csv works, as in are there columns? etc.
    Thanks,
    ttttt
    http://openoffice.org/- Microsoft Office without the Microsoft.
    [home page][forum]
    Versatile, free software

  • #10
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    csv is just items of information separated by commas, for example:
    Code:
    fred,smith,fred.smith@hotmail.com,0181 993 4533,31/07/52,true,false
    sometimes the first row in the file will contain identifiers for the columns. Fields that contain commas themselves are generally enclosed in "s, sometimes all data (or all text data) will be in "s regardless of its content (for consistency I guess).

  • #11
    Regular Coder ttttt's Avatar
    Join Date
    Oct 2005
    Posts
    372
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok, thanks.
    But with mysql, you can echo certain parts of each entry, by column. e.g.:
    PHP Code:
    <?php
    echo $data['id'];
    ?>
    Is that possible with csv?
    Thanks,
    ttttt
    http://openoffice.org/- Microsoft Office without the Microsoft.
    [home page][forum]
    Versatile, free software

  • #12
    $object->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Jun 2003
    Posts
    3,092
    Thanks
    2
    Thanked 23 Times in 23 Posts
    Refer to post #6 in this thread. The values you would echo out from that code are $col1, $col2, etc.
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    SNAP to it!

  • #13
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,073
    Thanks
    11
    Thanked 98 Times in 96 Posts
    the first line of a csv file usually contains the descriptions so when you load the below data with file() or fgetcsv() etc then $line[0] contains the descriptors

    ..........data.csv.........................................
    0 | id,name,colour /*descriptors not data*/
    1 | 1,apple,green
    2 | 1,banana,yellow
    ..etc

    from that file you could use $line[0] to give you a reference point
    $d=array('id'=>0,'name'=>1,'colour'=>2);//created from line[0]

    then $line[2][$d['color']];// would equal yellow

    you could abstract that further and build functions to convert your array into a mysql-like associative assay or object but the point here is that it's just a csv file, not a relational database so you are going to have to do a lot of work with your data if you want to use it just like MySQL.

    ...and this is the simple stuff when it gets to searching the data or trying to run queries against it then you will really hit the hard stuff, you can do it by creating separate index csv's etc but these have to be rebuilt constantly as your data changes and the text files get big.

    Can I ask why you don't want to use a DataBase ? is it simply not available with your hosting ?
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #14
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,795
    Thanks
    19
    Thanked 156 Times in 147 Posts
    If you are going to be searching data, XML seems like a better alternative (to CSV) as it is already separated into nodes. But XML (and CSV) is slower (usually) for large amounts of data, as has already been said.
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!

  • #15
    Regular Coder ttttt's Avatar
    Join Date
    Oct 2005
    Posts
    372
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by chump2877 View Post
    If you are going to be searching data, XML seems like a better alternative (to CSV) as it is already separated into nodes. But XML (and CSV) is slower (usually) for large amounts of data, as has already been said.
    Well, I tried to use xml, but I simply don't know how, and I was discouraged from doing it.
    The reason I don't want to use a database is that I've been trying for a very long time to get it working, but whatever I try, just doesn't work, I've posted here about it before, but I've done that quite a lot for simple problems. For example, cf helped me built two seperate pieces of code, but when I put them together with an if statement, they both refused to work.
    I would definately consider xml, but I have no idea what popping and pushing things means and don't know where to start.
    I don't have simpleXML or anything, just the base ingredients of php4.
    Thanks,
    ttttt
    http://openoffice.org/- Microsoft Office without the Microsoft.
    [home page][forum]
    Versatile, free software


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •