PHP - MYSQL to ClientDataSet - php

I don't know much about Delphi / ClientDataSets but I'm willing to look into it. I have a question before I pursue it though, to determine if what I want to achieve is feasible.
I want to use a PHP script to save a dozen subsets of my MYSQL database to CDS files once weekly. Is there a File specification that I can follow to create a CDS file? I'll be running the script on a shared web host using Linux, so I don't think running Delphi scripts on the server is viable.
Thanks!

There is a related question on Stackoverflow which includes a partial XSD:
Anyone that has a partial XSD that describes the METADATA section of Delphi TClientDataSet XML files?
You can use this XSD and an XML library to create XML files from your data which are compatible with TCLientDataSet, so they can be opened in a Delphi application.
I don't know PHP XML libraries, but in many languages XML libraries are able to create mapping code based on the XSD, which then can be used to read and write XML files based on the schema definition.

Related

Word to xml conversion

Here is my problem: My organization wants to upload word documents from users to the server. On the server side, the word document (enforced with styles) needs to be converted to XML format files. Next, I need to use php to parse the open xml formats files and put the content into the database. Does anyone know how to convert word to XML on server side automatically?Is there any API or sample codes for php to parse Open XML Formats? Your suggestions are appreciated.
Have you looked at using VBA?
I have had to do similar work and I've used VBA within a WSF or VBS file. If you're server is a Windows environment it will run right from the OS. You can execute this from PHP (not recommended) or drop the Docx file into a hot folder outside of the web server environment. I recommend the latter since the web server env. can introduce security issues.
Another note, if you want to separate content from styling, you're going to need to perform some post-processing on the output markup. Word is a "word" processor so styling is what it is designed to do. If this is a requirement, I would suggest moving to a structured, XML-based authoring tool instead.
Hope this helps!

File and Folder Attributes - Programming API

I knew that PHP is able to read file content by different ways, for example: fread, file_get_contents, file, readfile, etc.
Currently, I am looking for an API that can read real index of files and folders in specific partition or folder, for example:
drive d:\ in windows contains three folders (folder1, folder2, folder3), and each folder contains some files, we can get these directory structure using PHP (opendir, scandir, readdir, etc) and list them as I want, however, windows saved file and folder names inside hard-disk with their attributes (size, last modified, created on, etc).
How I can read hard-disc using PHP and retrieving all file and folder attributes for a specific path?
for instance, if we consider last modified time we can use (filemtime()) function, but this attribute not saved inside the file, its saved some where else inside hard-drive, other attributes also saved in other location not inside the file.
When windows user copying file from flash-drive to local hard, windows will copy all file and folder attributes and saves them inside local hard drive. When using PHP for copying file, it depends on OS to handle this job, its not native support (as I think) for file and folder operations.
Do you have any idea?
There are many recovery program that uses this technology for reading hard-drive indexes, however, for PHP: I cant find any source for this problem.
Applications if I get correct answer:
I can check if such file securely deleted from my hard-drive? I can create secure delete application using PHP, or clearing hard-drive indexes for a given file.
Your help appreciated.
Problems with the proposition
The attributes of files, such as timestamps, permission flags etc, are stored in the file system (FAT, NTFS, Ext3 etc). As you say some of them can be read using PHPs different file and directory methods, but they all act through the OS file system abstraction and cant have access to block level information on the disk, such as what precise byte on disk stores the archive flag for file X. The whole point of the OS and FS is to abstract away this information from the user/client programs.
As suggested there are external tools, written in c or similar, that does have this access and that you can call from inside PHP. If you want a 'native' PHP way of doing this you'll have to compile a c extension for PHP that exposes these low level functions to you.
I'd say external tools is the way to go if you want to stick with PHP but for the task at hand, as far as we can see from your description, I'd go with another language that has more low level access. Like C or C++. PHP is a high level language for HTML pre processing and as such is a poor choice for low level system programming.
Practical advice
After looking through the PHP documentation and assorted third party libraries:
An of the shelf solution for reading file system information on a file allocation table level doesn't exist for PHP. The lowest level you get is the fstat() function, and that is not very far for what you want.
External tools
No mater exactly what you want to do there is probably a small binary that does it. PHP can be integrated with these programs, as suggested elsewhere, via the exec() function. This is probably the easiest approach for you unless you have serious amounts of time and/or development resources to devote to this problem.
Wrapping a library
There are libraries that solves this problem for you, written in low level languages. An open source library can be wrapped with SWIG to expose it to PHP. This will give you access to the low level methods you need, but it's a non trivial task. These kind of libraries also often require sole access to the device while they work on it, something that is difficult to achieve in most normal operating environments.
Note also that you will probably need a library per file system. Microsofts VFAT extension to FAT12/16/32 requiers a licens to use. So if you want to work with FAT and have files with long names (not 8.3 format) you'll have to fork up some dough to be legit.
Low level implementation
A last middle ground would be to write your own CLI tool that uses an external library to access the low level FS functions. You can then use exec() from inside PHP to interact with your own implementation.
This might be a reasonable path if you cant find an existing tool that solves your problem and you are not willing to spend the time to wrap a library.
In closing
You give a very narrow problem description with little to go on as for what the application is about. A broader discussion (in another forum) might yield better results since the problem might be better solved in another way entirely.
I found something on PHP.net which appears to do what you want:
http://php.net/manual/en/function.readdir.php#103418
Edit: I mis-understood the question. Attributes such as the last modified time, last accessed date and the like are stored in the file systems master file table. As far as I can tell, this isn't accessible with PHP, and if you were to write your own method to do this then you'd also have to account for different file systems as they all handle the storage of these attributes in their own unique way.
It could be that to get all of the information you're looking for is not possible with PHP without writing some form of extension to PHP itself.
Edit 2: Upon researching a little more...
http://php.net/manual/en/function.fileinode.php
This function could be an interesting one to look at.
Well if I understand correctly you just want to securely delete a file. You can just call [shred][1]
[1]: http://linux.die.net/man/1/shred via system or exec if you are on linux and you are good to go

Generating PHP file to cache XML data

I'm currently developing a Web application with Zend Framework and PHP 5.3. I have a XML file that contain configs and mapping information (+- 1500 lines). On each request I perform an xpath query to get information from that XML file. The information that is found in the XML file is static and do not change after the deployment of the application.
It is a good practice to generated a php file that contain the XML information in a static arrays on the first request and then load that php file on every request to get the information instead of doing queries on the XML?
You can cache the parsed config file as source file with var_export.
Generating code to cache resources is implemented in several places in Zend Framework, for example autoloader, so I presume it is good practice.
There is also another way to cache it - with serialize (make sure to serialize an array, not for example a SimpleXML object) or Zend_Cache which does more or less the same but is more flexible as to how the result is stored.
Since the XML not changes after deploy, i think it would be the best to transform that XML in your local dev env, and not on the productive system when needed. Its not a good idea to generate source on the productive system that will be automatically included without any validation.
I'm not very familiar with XSLT, but it might be an option for you, according to the concrete structure of that XML.

PHP xml configuration package or framework?

I am looking for some type of framework or package or library for PHP that would manage my PHP web apps configuration parameters. Is there such a thing? Rather than repeatedly opening a file and reading and parsing the contents, is there something already existing I can use?
Take a look at Zend_Config, you have there an xml version, but also ini, json or yaml.
update
I don't understand exactly your usage scenario and the main idea of Zend_Config is to remove the configuration data from various parts of the application and to put it in only one place. But you can adapt it to your use. If you have a config file with your users to be parsed, you can update that config independently and you application does not have to know how many users are in the file.
I would have liked to have used Zend_Config but just couldn't get it to work. I settled for the less programatically sexy alternative : SimpleXMLElement. Sometimes, in programming as in life, we choose to settle for the practical rather than the sexy. A Volkswagen instead of a Ferrari. Sarah Rodriguez instead of Pamela Anderson. Now I need to find something for Javascript. Any suggestions?

Best design for PHP/ASP application that makes calls to remote servers

We run multiple Windows/IIS/.Net sites (up to 30+ sites per server). Each site is customized for the individual customer via a configuration file that contains the settings.
I am tasked with writing a small tool that will 'grep' all of the config files on a certain server for a particular config setting (or settings) and return the values for a nice tabled web page display. It will save many groups lots of time, especially since most groups don't have access to production servers, but they need to know how a customer is currently configured.
I have working code that finds all .config files from a starting path, I can easily extend this to do my grep'ing. Here are the challenges:
I want to aggregate this data from MULTIPLE servers. That means, the tool will be hosted on its own server -- and will make calls to a list of servers.
I'm limited to using .NET/ASP on the actual servers (they won't install PHP on IIS), but I'm writing the tool in PHP.
PROPOSED DESIGN: From my vantage point, I'm thinking the best way to accomplish this is to write my PHP tool and have it make AJAX or CURL requests to ASP scripts that live on each server in the list. Each ASP script could do the recursive directory parsing to find the config files and individually grep the files for the data, and return it in the RESPONSE.
Is that the best way to accomplish this? Should the ASP or PHP side do the 'heavy lifting'? Is their a recommended data format I should be using to pass the data.
Any ideas or samples would be great. If you need more info, I can provide!
Thanks!
Update: Here's an example of a config. Its a basic ASP file that gets included in other scripts.
custConfig1 = " 8,9,6:5:5 "
custConfig2 = " On "
I think you're bang on using PHP for the "receiving" script, and pretty sure you have that in hand.
Based on the format of your example config file, you could use ExecuteGlobal in classic ASP to load each file as you loop through them in your recursive directory lookup. Then you can use the custConfig1 et al. names in your script. e.g. (pseudo)
for each file
output("custConfig1") = custConfig1
next
Return what you need as JSON using a handy library and then do all the "hard" work of collating it and outputting it in PHP.
Yes, "grep" (if by that you mean importing a text file and using reg expressions to navigate it) isn't the best solution, in my humble opinion, use either JSON or XML as the format, and use PHP's built in XML or JSON tools.
JSON: http://php.net/manual/en/book.json.php
XML: http://php.net/manual/en/book.simplexml.php
You could use the DOM to navigate XML alternatively to SimpleXML, but SimpleXML is easier to learn (again, in my opinion) and will work for your needs.

Categories