This is a pretty straightforward question: is there any way of creating an MS Access database file from scratch using PHP? I strongly suspect the answer is no out of the box (using PDO with the ODBC driver pretty clearly demands an existing file for the connection string), but perhaps there’s a library I haven’t found. Currently I’m using an empty .accdb file as a template and making a copy before CREATE-ing tables in it, but I’d like to skip that step for security reasons if nothing else.
You can't, because the ODBC driver needs a database(!) to connect to.
Your current approach, copying a template file, is clean and simple and, except if the file can be replaced, also safe.
Related
I have written an app in PHP which outputs (and receives) RSS feeds.
I want to get the app to email when there is a new item in one of the feeds.
I am looking for an easy way for me to do this without storing contents on a database. Is there a script that does that? If not how is the best way of doing this?
I thought about storing the latest items for each feed in separate text files and marking them as sent when the email was sent. It seems a bit clunky, but might work. I am not sure of the best way to format the text file.
Any ideas would be appreciated.
I know that you're opposed to using a database, but not opposed to storing data in files. Perhaps you wouldn't mind using a database like SQLite.
SQLite databases are stored (and accessed) in files, it doesn't require any installation or a database server, just the file system. Read the linked page above.
It would be more efficient than just flat text files, and take you less time to set up. For a small simple application this could be the right solution.
You should use PDO as the database driver in PHP (not the SQLite class). It's enabled by default on most systems and won't require any edits to php.ini. Using PDO also makes it very easy if you want to switch to a MySQL (or other) database later.
From the installation manual:
PDO and the PDO_SQLITE driver is enabled by default as of PHP 5.1.0.
If the user has less than PHP 5.1 installed, then your script will probably be broken in another way. I find that most common users have 5.3.x.
I've always used MySQL with PHP and on my site I added a chat system that uses MySQL which as you would know is VERY database heavy so I think I'm going to switch it over to XML files for each user just for the chat system to take all the load off of the DB.
I have never used XML with PHP before so I was looking for information, and found that the queries are pretty similar to MySQL.
Here are my questions:
Is it the client writing to the file or the server writing to the file?
Do I have to chmod them as 777?
Do I also have to chmod the XML file as 777?
If I do have to set the permissions to 777, does that drastically decrease security and is there any way to tighten that up?
Does anyone have any tutorials they would recommend me to as well? Most of the stuff I found is from 2003 - 2005. Don't know how much has changed in it.
Hope it's cool I ask this question here.
Thanks a bunch
-Sal
First off, it seems like a very bad idea to do something that is very database intensive in xml, it is going to be a lot more intensive that way.
To answer your question; It is always the server writing to the server filesystem. you only need to provide write access to the user running apache (and consequently php).
I suggest you stick with mysql for chat but look into DOMDocument to learn more about xml
My project is a collection of PHP scripts using MySQL as a database and needs to be installed locally using WAMP/LAMP/MAMP.
Previously I've been sending the users a link to a zipped archive and having them overwrite it, but since I took the plunge to GitHub, I've realized that there are far better ways; namely Service Hooks in GitHub. However, this would work fine as long as I don't alter the database in any way, which is a good possibility.
I've been toying with the idea of how I would implement this, but I can't find a clear solution. So far I've concluded with that I need to have a directory (say update/) which contains .sql files for each update. The PHP script will then check said directory for a file corresponding with the new version number (not sure how I will define a version number; I was thinking of using the commit ID, but that won't be available until after the commit, so...).
I would love some input on this!
Here's how I would tackle this (not the most elegant or performant):
Add a flag in the DB with a version number
Add a min-version number in your DB layer PHP file
Check that the DB version is greater than the min-version
If it is: continue about your business
Else: Run the PHP file in update/ which would have a series of ALTER TABLE commands to be run on the DB server
Update the min-version number in the DB to the latest number
All done
Alternately instead of querying the DB you can have a file which is generated by your DB interface PHP file (and ignored with .gitignore) which you can just as above.
I would really recommend checking out Doctrine and its migration feature.
This does exactly what you are looking for, plus you get a very nice tool for working with all other aspects of your database handling.
Is it possible to write .MDF files using PHP. I have a simple HTML table - x columns, y rows that I wish to convert into a MS Access dataset. There are no foreign keys or anything exotic, just a number of rows and columns.
I have Google searched but the only advice I seem to be able to find is to save it as a .CSV. Unfortunately this isn't acceptable for my client. They want to simply be able to double click the icon and have the database load up in Access (Seems you have to import csv files and can't just double click them).
Those are actually two different problems:
1) Parsing HTML to separate values
Since you seem to have found a way to export to csv, I won't be answering this. You already got your parser then.
2) Create an mdb file.
You can use odbc to talk to Access, that is, if you are in Windows. That means that PHP must be installed on a Windows machine. I'm not aware of any Linux drivers for Access..
You can use odbc_connect to connect to the database:
$conn = odbc_connect("dbname","" ,"");
From there, working with the database is pretty similar to MySQL as long as you use the ODBC functions.
The only problem is creating the actual MDB. This cannot be done in ODBC, you'll need the JET engine. It may be possible to create an MDB file from PHP, but it may be easier to create an empty MDB once, and copy that file from PHP whenever you need a new database.
Jackcess is a pure Java library for reading from and writing to MS Access databases. It is part of the OpenHMS project from Health Market Science, Inc. . It is not an application. There is no GUI. It's a library, intended for other developers to use to build Java applications.
http://jackcess.sourceforge.net/
But an MDF file is not a standard Access file extension. MDB and MDE are while MDW is for user level security.
Have not tested this but this might help you:
http://devzone.zend.com/article/4065
Note that active development of MDB Tools has moved from Sourceforge to Github
https://github.com/brianb/mdbtools
Is there a php editor on the market witch can read sources straight from a mysql database?
No....and maybe.
There is no reason why anyone should write a MySQL based editor.
Your best chance to archive this is to find a greedy and/or lunatic programmer that will write you a MySQL-virtual drive.
Yes this IS possible, and at least on windows it does not take much skills.
Well, you could use one of the existing php online editors, and hack the Horde VFS backend in, allowing you to read local files or a database file storage. Another alternative was writing your own FUSE driver. Most sensible however would be to make your database contents available over WebDAV, allowing you to use Eclipse or so