I have a JSON file which displays data from my MySQL database.
I have an app that fetches and stores that data in the app on the first launch. It's stored in CoreData so the user doesn't have to be connected to internet to be able to use the app.
I'd like to update the data if anything has changed in the database. The first method I've been using is storing the total length of the JSON data fetched and then comparing it, but I was wondering if there was a better method to do this.
Could I fetch the modification date of the JSON file? If so, how?
Thanks
Storing the length will still leave you with a place for error, and the data could change but keep the same length, what can be more efficient is to store the checksum of the file in your app and whenever it checks for updates from the server it will compare it with the newly generated file's checksum, if the checksum matches then there is no changes. you can use md5_file for this.
You can also cut bandwidth, please check ETag that could save you some time. http://bitworking.org/news/ETags__This_stuff_matters
Related
I have one sql server 2008 database table in which i am storing all types of documents i.e. doc,docx,pdf,image.
the datatype of the data field is 'image'.
Data is stored in database.
But i need to retrieve it and display it in my php page.
I dont need to save or change it but user only need to view that document.
I am using simple select query like
select docid,docname,data from documents
The data field results in System.Byte[].
What do i need to do to print that document in my php application ?
Please help me.
Thanks in Advance.
Mausami
To display directly from memory you're going to need to know the mimetype. In tables that store random files like that the usual process is to also store the type of file and mimetype in another field. Do you have access to that kind of data?
If you do know the mimetype then you can notify the browser what to expect with the technique used the answers posted to this similar question. Google Header Content-Type for more information.
If you don't know the file mime type then your probably going to have to save the binary to a file locally on your webserver and then attempt to display it from there and hope the browser knows what to do with the file type.
I'm using WordPress and use the API data with JSON format from a source for my site content, for example: http://api.source.com/data.json
But loading of my site take a bit longer because every time the page loaded will always take and read the file from the source, the question is how can I store the JSON file to WordPress directory and automatically update it every 12 hours?
Sorry for bad English but hope you got my point, Please help!
There are multiple options.
Use memcache -> Store the retreived json in memcache, and expire it after every 12 hours. This would be the fastest lookup.
http://www.php.net/manual/en/memcache.examples-overview.php
Database -> Store the retreived json in a database table with a key, you can use varchar , text , or blob datatype based on size of your json.
Write to a file -> Write the json to a text file in any of your directory which has write permissions,and read it from there.
http://php.net/manual/en/function.file-put-contents.php
Just a quick question I am wanting to allow users to link there facebook account to my new product, and I am wondering how do I take there facebook photo URL and save it as an image in BLOB formate for MYSQL
I am using this example to connect to Facebook
https://github.com/facebook/connect-js/blob/master/examples/jquery/login.html
and to send the image to my server I use the $.ajax formate to submit it to the core.php (I have not coded this yet, as I need to know the best way.
Well my first recommandation is to NOT store image data in your database unless you absolutely need that in your database backups. You will clutter your database massively. Instead, just get the url to the picture using the server-side $facebook class, and just "file_get_contents" it to your php memory.
Then dump it on disk and save a reference of that dumped image in your database. It will do much more good to your database this way.
Else, if you really want to save it to a BLOB, use the same method to fetch the image to memory and then use the hex() function to transform it to a textual representation that can be fit into an INSERT/UPDATE query...
Just save a reference to the location where Facebook stores the image. That way you can abuse their servers (which are very nice/fast) and just serve image tags that refer to their servers.
Also when you save images to a database you lose the native compression that you get when you save an image to the filesystem, so you bloat your data storage size for not much reason (backups are easier I suppose).
I am trying to create a world application using jQuery (JS) and PHP. I originally tried doing this by using a MySQL database, which didn't work well - the server got overloaded with database queries and crashed.
This time I want to store the data in a text file... maybe use JSON to parse it? How would I do this? The three main things I want are:
Name
x-position
y-position
The x and y positions are given from the JS. So, in order:
User loads page and picks username
User moves character, the jQuery gets the x and y position
The username, x and y position are sent to a PHP page in realtime using jQuery's $.post()
The PHP page has to find some way to store it efficiently without crashing the database.
The PHP page sends back ALL online users' names and x and y coordinates to jQuery
jQuery moves the character; everyone sees the animation.
Storing the data in the file instead of the MySQL database isn't an option if you want to improve performance. Just because MySQL stores its data in the files too, but is use some technics to improve performance like caching and using indexes.
The fastest method to save and retrieve data on server is using RAM as a storage. Redis for example do that. It stores all the data in the RAM and can backup it to the hard drive to prevent data loss.
However I don't think the main problem here is MySQL itself. Probably you use it in an inappropriate way. But I can't say exactly since I don't know how many read and write requests your users generate, what the structure of your tables etc.
Text files are not the best performing things on Earth. Use a key-value store like Redis (it has a PHP client) to store them. It should be able to take a lot more beating than the MySQL server.
You can store the data in a text file in CSV (Comma separated values) format.
For example, consider your requirements.
1,Alice,23,35
2,Bob,44,63
3,Clan,435,322
This text file can be stored and read anytime, and use explode function to separate values.
I'm trying to figure out a way to store files in a database. I know it's recommended to store files on the file system rather than the database, but the job I'm working on would highly prefer using the database to store these images (files).
There are also some constraints. I'm not an admin user, and I have to make stored procedures to execute all the commands. This hasn't been of much difficulty so far, but I cannot for the life of me establish a way to store a file (image) in the database.
When I try to use the BULK command, I get an error saying "You do not have permission to use the bulk load statement." The bulk utility seemed like the easy way to upload files to the database, but without permissions I have to figure a work-a-round.
I decided to use an HTML form with a file upload input type and handle it with PHP. The PHP calls the stored procedure and passes in the contents of the file. The problem is that now it's saying that the max length of a parameter can only be 128 characters.
Now I'm completely stuck. I don't have permissions to use the bulk command and it appears that the max length of a parameter that I can pass to the SP is 128 characters.
I expected to run into problems because binary characters and ascii characters don't mix well together, but I'm at a dead end...
Thanks
In general, we don't pass binary data in SQL. We upload the file to the server, then load the image from the server into the database.
Load the image into the database from a file:
UPDATE images
SET image = LOAD_FILE('images/myimage.jpg')
WHERE image_id = 1234
Get the image back out to a file:
SELECT image
INTO DUMPFILE 'images/myimage.jpg'
FROM images
WHERE image_id = 1234
Here is an example I've found in David Hayden's blog.
It's a c# example, but the steps should be similar in PHP:
Convert your uploaded file to a byte array
Execute dynamic TSQL on the server