TinLy Posted March 11, 2019 Share Posted March 11, 2019 Hello everyone, I just started coding php. I have a website on which is connected to my database by php file on server. but I had a problem, I need to check when my database changes then "do something". But my "Hosting" has counted my "query" and the problem is "maximum query per hour". Is there any way to check my database without running "query". THANKS? <?php $table = $_GET["table"]; $col = $_GET["column"]; $db_connect = mysqli_connect("server", "user", "pass", "dbname"); if (!$db_connect) { die('Could not connect: ' . mysqli_error()); } else { echo 'Connected successfully'; } $sql = "SELECT $col FROM $table"; $result = mysqli_query($db_connect, $sql); if (mysqli_num_rows($result) > 0) { $row = mysqli_fetch_assoc($result); echo "". $row[$col].""; } else { echo "0 results"; } mysqli_close($db_connect); ?> Quote Link to comment https://forums.phpfreaks.com/topic/308447-php-help/ Share on other sites More sharing options...
kicken Posted March 11, 2019 Share Posted March 11, 2019 Not really no. If you want to know the content of your database you have to query for it. If you explain more about what your goal is then perhaps there is an alternate solution. For example, maybe you should just "do something" in the same place that you change your database, then you won't have to query it constantly to detect a change. 1 Quote Link to comment https://forums.phpfreaks.com/topic/308447-php-help/#findComment-1565150 Share on other sites More sharing options...
TinLy Posted March 11, 2019 Author Share Posted March 11, 2019 12 minutes ago, kicken said: Not really no. If you want to know the content of your database you have to query for it. If you explain more about what your goal is then perhaps there is an alternate solution. For example, maybe you should just "do something" in the same place that you change your database, then you won't have to query it constantly to detect a change. Hi kichen, The problem is that I need to communicate my website with another customer (my pcb) by through my database. Do you have any ideas for this case. THANKS Quote Link to comment https://forums.phpfreaks.com/topic/308447-php-help/#findComment-1565151 Share on other sites More sharing options...
taquitosensei Posted March 11, 2019 Share Posted March 11, 2019 You could still write to your database. But at the same time to write to a json file or some other flat file format so that you know it's changed. Then instead of querying the database to find out if the database has changed look at your file. 1 Quote Link to comment https://forums.phpfreaks.com/topic/308447-php-help/#findComment-1565156 Share on other sites More sharing options...
taquitosensei Posted March 11, 2019 Share Posted March 11, 2019 Either that or switch hosting plans/companies. Find one that doesn't limit the number of queries per hour. Quote Link to comment https://forums.phpfreaks.com/topic/308447-php-help/#findComment-1565157 Share on other sites More sharing options...
ginerjm Posted March 11, 2019 Share Posted March 11, 2019 Can you explain better what you mean by "changed database"? A database is a set of tables of which your server/account may have several. Are you talking about a chang e to a single table? How do you tell if a table has been changed? Query every single record and compare it to something saved? 1 Quote Link to comment https://forums.phpfreaks.com/topic/308447-php-help/#findComment-1565158 Share on other sites More sharing options...
TinLy Posted March 12, 2019 Author Share Posted March 12, 2019 12 hours ago, taquitosensei said: You could still write to your database. But at the same time to write to a json file or some other flat file format so that you know it's changed. Then instead of querying the database to find out if the database has changed look at your file. Hello taquitosensei, actually I try to use the free server for my website because I use it to learn better without having to pay. And I used the same method as you said. My server (web) contacted my client (pcb) via a file.txt. But you know what, speed is not acceptable. it's too slow 12 hours ago, ginerjm said: Can you explain better what you mean by "changed database"? A database is a set of tables of which your server/account may have several. Are you talking about a chang e to a single table? How do you tell if a table has been changed? Query every single record and compare it to something saved? Hi Ginerjm, thanks for your interested. I only care 1 column in my table. If it's changed then "do something". Quote Link to comment https://forums.phpfreaks.com/topic/308447-php-help/#findComment-1565172 Share on other sites More sharing options...
ginerjm Posted March 12, 2019 Share Posted March 12, 2019 (edited) 'One column'?? You mean a single column on a single record or that singled column across all of the records in that table? And how do you know that it has changed? Are you saving the original value somewhere in your session or in another record? Edited March 12, 2019 by ginerjm 1 Quote Link to comment https://forums.phpfreaks.com/topic/308447-php-help/#findComment-1565176 Share on other sites More sharing options...
TinLy Posted March 13, 2019 Author Share Posted March 13, 2019 15 hours ago, ginerjm said: 'One column'?? You mean a single column on a single record or that singled column across all of the records in that table? And how do you know that it has changed? Are you saving the original value somewhere in your session or in another record? Hi Ginerjim, I need to check a signle column on a signle record. I save last "content" in 'var' and compare in next cycle. But if i do like this, i have to run "query" again, agian.... many time per hour -> got over maximum litmit "query" per hour. It's posible get "content" of a colum without run "query". Or can run only one "query" after that just re-use. THANKS Quote Link to comment https://forums.phpfreaks.com/topic/308447-php-help/#findComment-1565189 Share on other sites More sharing options...
ginerjm Posted March 13, 2019 Share Posted March 13, 2019 Simple question now. Who is doing the changing? Is it a script that you have control of or access to ? I'm sure you can see where I am going here. 1 Quote Link to comment https://forums.phpfreaks.com/topic/308447-php-help/#findComment-1565192 Share on other sites More sharing options...
TinLy Posted March 14, 2019 Author Share Posted March 14, 2019 11 hours ago, ginerjm said: Simple question now. Who is doing the changing? Is it a script that you have control of or access to ? I'm sure you can see where I am going here. Hi Ginerjm, "Who is doing the changing" answer my web & client (pcb) both can "change" that database by php file. My own server. THANKS. Quote Link to comment https://forums.phpfreaks.com/topic/308447-php-help/#findComment-1565216 Share on other sites More sharing options...
kicken Posted March 14, 2019 Share Posted March 14, 2019 (edited) @TinLy, Unless your client has direct access to your database some how, presumably they are changing it by making a request to some script you have on the server and sending it information. If that's true then you can simply "do something" at that point rather than having to constantly poll your database. Otherwise, stick with polling if you want but limit your query rate to something acceptable which might mean the detection of said change may be delayed a bit. For example, maybe wait a minute etween checks, or 5 minutes if that's still too much. You're being too vague about your situation to really provide any better help. If you need more help you'll have to start getting into specifics instead of just saying "something changed", "do something", "client", etc. Edited March 14, 2019 by kicken 1 Quote Link to comment https://forums.phpfreaks.com/topic/308447-php-help/#findComment-1565217 Share on other sites More sharing options...
TinLy Posted March 14, 2019 Author Share Posted March 14, 2019 20 minutes ago, kicken said: @TinLy, Unless your client has direct access to your database some how, presumably they are changing it by making a request to some script you have on the server and sending it information. If that's true then you can simply "do something" at that point rather than having to constantly poll your database. Otherwise, stick with polling if you want but limit your query rate to something acceptable which might mean the detection of said change may be delayed a bit. For example, maybe wait a minute etween checks, or 5 minutes if that's still too much. You're being too vague about your situation to really provide any better help. If you need more help you'll have to start getting into specifics instead of just saying "something changed", "do something", "client", etc. Hi Kichen, thanks. i am not very well about assamly. My case it's look lkie this: At the time my "CLIENT" will read php file -> change database (a col). My "WEB" have to show "Content" in database(a col) i want it show imedicly no delay or very "shorts delay". But how i can do it -> only continuity read my database(a col) right ???. Quote Link to comment https://forums.phpfreaks.com/topic/308447-php-help/#findComment-1565218 Share on other sites More sharing options...
ginerjm Posted March 14, 2019 Share Posted March 14, 2019 As Kicken has already said - if YOUR code is doing the updates that you are trying to monitor afterwards, then by all means alter your code to send you a notification via email or with a simple text file on your server that tells you when and what changed. 1 Quote Link to comment https://forums.phpfreaks.com/topic/308447-php-help/#findComment-1565221 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.