Jump to content

Recommended Posts

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);
 ?>

 

Link to comment
https://forums.phpfreaks.com/topic/308447-php-help/
Share on other sites

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.

 

  • Like 1
Link to comment
https://forums.phpfreaks.com/topic/308447-php-help/#findComment-1565150
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/308447-php-help/#findComment-1565151
Share on other sites

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?

  • Like 1
Link to comment
https://forums.phpfreaks.com/topic/308447-php-help/#findComment-1565158
Share on other sites

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".

Link to comment
https://forums.phpfreaks.com/topic/308447-php-help/#findComment-1565172
Share on other sites

'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 by ginerjm
  • Like 1
Link to comment
https://forums.phpfreaks.com/topic/308447-php-help/#findComment-1565176
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/308447-php-help/#findComment-1565189
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/308447-php-help/#findComment-1565216
Share on other sites

@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 by kicken
  • Like 1
Link to comment
https://forums.phpfreaks.com/topic/308447-php-help/#findComment-1565217
Share on other sites

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 ???.

Link to comment
https://forums.phpfreaks.com/topic/308447-php-help/#findComment-1565218
Share on other sites

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. 

  • Like 1
Link to comment
https://forums.phpfreaks.com/topic/308447-php-help/#findComment-1565221
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.