Mysql Feed to make tables in html/php - php

Hello all i have a quick question
Is there a way i could make a php system that could read a mysql database and make multiple tables based on that and new information?
So say if we implemented it and we added new information to the database it would automatically add a new table into the php page or would that have to be done manually
I just wanted to know if it is doable before i start to look deeper into the code of it

Yes, it is doable.
There is nothing that can prevent you from doing that.
Taking into account your comment:
Yes it's still doable. Terribly inefficient but doable. You can use AJAX or COMET to update information on your page.

Yes.
Look at phpMyAdmin for an example of what you are talking about.

Related

Showing Data in MySQL Database In Realtime

I am building a weather station that will update the weather in "real-time" to a MySQL Database. To give the feel of "real-time" without taking up a ton of space on my MySQL server, I have my weather station updating a single cell in the MySQL database every few seconds. I would like to set up a way for a website to view this change in realtime without refreshing the page. I have tried researching a lot, but I can't quite find what I am looking for (at least with more of an explanation into the JQuery and how it works). Most answers have partial as people have a lot more experience.
I have a little experience with PHP and MySQL (I have just started learning a couple of months ago). This project is more of a way to learn JQuery and AJAX (along with PHP and MySQL). Frankly, I don't know a ton as I am just starting into programming.
If I could get a bit more of an explanation into how the JQuery works and what files I need to be placing the information in, that would be great (a lot of other similar answers had a separate "server" file and a "client" file in PHP. Do I really need that?).
I just don't know where to begin or what to put in what files. Maybe I need a tutorial? Thanks.
I think what you are looking for is "Push Technology". But, as a beginner like me, I would introduce you to try out "long pulling". Although is not the best method, you can learn how real-time update works.
I suggest you create a normal working AJAX, then use the code below to repeatedly call for updates from the server.
jQuery(document).ready(function () {
interval = setInterval("checkNewUpdate()",4000); //Set interval for accident checking ajax
}
This function basically retrieves information from the database every 4seconds. This method is not so efficient, but I hope would help you to kick start in push technology.
Visit How do I implement basic "Long Polling"? for more information.
I suggest you to create a function to check database status, something like count row in the database or something else like that... the return must be simple a data like number , true or false (not a long data) with interval .. and when it change the fetch function will run

Recreate a database using existing php code

So I have an old website which was coded over an extended period of time but has been inactive for 3 or so years. I have the full PHP source to the site, but the problem is I do not have a backup of the database any longer. I'm wondering what the best solution to recreating the database would be? It is a large site so manually going through each PHP file and trying to keep track of which tables are referenced is no small task. I've tried googling for the answer but have had no luck. Does anyone know of any tools that are available to help extract this information from the PHP and at least give me the basis of a database skeleton? Otherwise, has anyone ever had to do this? Any tips to help me along and possibly speed up the process? It is a mySQL database I'm trying to use.
The way I would do it:
Write a subset of SQLi or whatever interface was used to access the DB to intercept all DB accesses.
Replace all DB accesses with the dummy version of yours.
The basic idea is to emulate the DB so that the PHP code runs long enough to activate the various DB accesses, which in turn will allow you to analyze the way the DB is built and used.
From within these dummy functions:
print the SQL code used
regenerate just enough dummy results to let the rest of the code run, based on the tables and fields mentioned in the query parameters and the PHP code that retrieves them (you won't learn much from a SELECT *, but you can see what fields the PHP code expects to get from it)
once you have understood enough of the DB structure, recreate the tables and let the original code work on them little by little
have the previous designer flogged to death for not having provided a way to recreate the DB programatically
There are currently two answers based on the information you provided.
1) you can't do this
PHP is a typeless language. you could check you sql statements for finding field and table names. but it will not complete. if there is a select * from table, you can't see the fields. so you need to check there php accesses the fields. maybe by name or by index. you could be happy if this is done by name, because you can extract the name of the fields. finally the data types will missing. also missing: where are is an index on, what are primary keys, constrains etc.
2) easy, yes you can!
because your php is using a modern framework with contains a orm. this created the database for you. a meta information are included in the php classes/design.
just check the manual how to recreate the database.

Should I use phpmyadmin or php to add content a to a database?

My knowledge of MySQL is very basic here... so I'm just wondering if I want to create a table in a database, and add rows to that table, is it best to do so through phpmyadmin or should I do so in a PHP file?
Of course you can do it programmatically, maybe for your project you'll have to do it later anyway. But to get used to this whole SQL stuff, maybe it would be better to use some administration tool, like the mentioned phpMyAdmin or MySQL Workbench. I wouldn't recommend the commandline tool for starting, except you like a puristic commandline environment.
I just found this phpMyAdminDemo. Maybe it's good to start with, if you really want to use PHPMyAdmin. But if you don't have to, I would recommend to use Mysql Workbench, because it has a nice user interface and I hope it's relatively easy to deal with. A really nice feature is, that you can create diagrams of your database in the GUI, and forward it to the database. Even if you modify the diagram (e.g. adding columns), you can synchronize it with the database with only a few clicks. Additionally to that you can enter and edit data with Workbench as well.
So you might have a basic database structure then - after you struggled through some select statements in PHP like in PHP MySQL Select you will maybe finally get to the point where you want to: Like creating tables with PHP and MySQL or inserting data with PHP and MySQL
[Edit] I re-read your question as your title and question don't match. To answer your question; Creating the database schema is what phpmyadmin was made for. For managing data see what I wrote below.
Depends on your situation. If there's only you and just you managing the content then it can be an easy way to insert and edit data quickly. If you want to do anything advanced, for example:
WYSIWYG (HTML editing) or
Validation
then you'll need to make something yourself. I wouldn't recommend you have a client using a CMS to edit through phpmyadmin as they're given too much power and could screw things up.
I'd suggest using phpmyadmin as its pretty easy for novice users. Here is a very detailed article to add a table in phpmyadmin - http://php.about.com/od/learnmysql/ss/create_tables.htm

Live tracking session variables from db

I've been looking for an easy way to track my current session variables on my desktop in order to have an eye on them.
My website uses Joomla and session variables are stored in MySQL by PHP.
What I'd like to achieve is a 'widget' or 'snippet' which could show on my Windows 7 desktop current session variables, and how they change during a visit on the website.
In fact the session state is stored in a table like:
session_id varchar(32)
data varchar(20480)
userid int(11)
So let say one solution could be retrieving first two columns by my userid with a SQL query and parsing 'data' column, which is in JSON format, into an 'snippet' object.
I don't know how to write widget/snippets and I don't expect anybody to write me one, I just wonder if such thing exist to make my developing easier.
Well, if you want to hack together something, I've got a couple of crude suggestions.
Write a simple SQL query ordered by date, throw in some HTML and add javascript to auto refresh the page, say every 30 seconds. Now you just need a tab open to monitor your sessions.
The same thing as above but instead of HTML, output XML in the feed format. Then use any feed reader software which usually has desktop widgets and alerts etc.
Good luck!
Well, it's been long time since I asked this question. So far, the best option I've found was PHP Quick Profiler tunned a bit up for Joomla Framework. Soon, I gonna post a tutorial how to implement this for Joomla. Should anybody want to hurry me up do not hesitate :)

PHP page counter, Database driven VS File .. which one better?

as the title of the question suggests, my question is simple, which one is better in terms of performance knowing that i'm on a linux shared hosting, siteground.. i'm capable of coding both, i actually coded a one that updates the DB, but from reading around some people suggested to insert and not to update.. any feed back is much appreciated..
thank you.
Use a database! Since you will have multiple people accessing your site, writing to one file will either mean blocking or having the count overwritten.
By using a database and inserting, you don't have to wait for other clients and you are safely allowing concurrent access. you just get the count by doing a select count(*) from countTbl
What are you storing in the database? If it´s just that one number (the page counter), I would not use a database but if you are storing data for each visitor, a database is the way to go.

Categories