Jump to content

Help on Fundamental


oceans

Recommended Posts

Dear People,

 

I need a very important advice.

 

My experience: I have done databases using VB, Winsock. It is relatively tough, but you get all flexibility & security is iron clad as you can define your protocol, and “malicious data” dumps, make multi thread to become single thread FIFO.

 

I need advice:

 

Is the PHP-MySQL multi threaded? That means, at any one instance, will MySQL be serving a more then one page? My intension; though MySQL can server (n number) of pages at any instance, it should NOT serve more then one page simultaneously. Reason, what happens if one table gets “updating”, and second comes for another process on the same table?

 

Is the PHP-MySQL FIFO.

 

Link to comment
Share on other sites

mysql can access information to more then one computer at the same time... besides... mysql's connections can take litterally milliseconds to finish... the chance of 2 computers connecting at the same time would be a once in a lifetime fluke... :D

Link to comment
Share on other sites

That is a good question. I am not sure as to the actual answer to your question, however it would not be very hard to "lock" a table when needed.

 

If I were doing this, then I would do it like so.

 

1 field in the tables you want to lock called locked. It accepts a 0 or 1. 0=no 1=yes

 

Generally when you want to edit records, it is a 2 part process. 1st you have to get the data from the database and display it in a form or whatever.

 

the second part is the actual update process.

 

I would simply make the default locked state 0. When you grab the data from the database to edit it, you check and make sure the data is in 0 (unlocked state). If so, get the data and run a query to change the locked state to a 1 for that record.

 

When you update it, you set that state back to 0.

 

It sounds like a lot of extra work, but it is actually very simple and would only require 4-5 extra lines of code.

 

Hope this helps ya some.

Link to comment
Share on other sites

do you know how to do basic select queries and update queries? Do you know how to do an if / else statement??

 

I am happy to help with problems in coding, but no one in this forum really wants to write your scripts for you.

 

Here is the basic principle.

<?php
// run query and get data you want
// use while loop to go through the results
// set variables for each element in the database you want to work with
// run if / else statement to see if table.locked is set to 1
// if it's a 1, the table is locked
// else it's a 0 it is not locked
// get all data you want to edit
// run update query and set locked to 1 for the row you are working with
// make changes in form and update
// when you update the information in the database, set locked back to 0 and exit the code.
// your data is now updated and the lock has been set back to unlocked state

?>

Just basically take the comments and create the proper code for each line. You may have to change some things, but its pretty much laid out there

 

Nate

Link to comment
Share on other sites

Dear Chronister,

 

You misunderstood me  ;) , I was requesting for the "locking database command syntex" I will try inserting into my code.

 

One question here, if two request comes, while one is being worked (locked), (i) will the second waits for the first to finish or (ii) it just sees it is locked and does nothing and gets out.

Link to comment
Share on other sites

it will do whatever you want it to do..

 

You specify what is to happen inside your code. There is no locking database command.

 

I am simply suggesting that you can place a field in your database called locked and make it so a 0 is unlocked, and a 1 is locked. Write your code to look at that piece of data and if it is 0 make it so you can do whatever you want with that data, if it is 1, it means it is locked. You would then create code to handle it however you want. If you want a message to appear saying "Sorry, this field is locked... Please try again later" you would do something like this..

 

<?php

if($locked_db_field =0){  // $locked_db_field should be changed to YOUR variable for this field
   // grab the data and do what you want with it
}
else
{
  echo 'Sorry, this field is locked... Please try again later';
}

?>

Link to comment
Share on other sites

I use to do these jobs in my server side.

When I am doing PHP I presumed that I am only doing client and have no control over the server.

Yes I can implement your suggestion, but can you suggest a "Sleep" code which does not consumes rosource while looping, I had this probelm in VB, eventually I came up with a timered loop which almost uses 0 resource while looping

Link to comment
Share on other sites

PHP is a server side language. It has nothing to do with client side. Once it reaches the client, it has done all that it is going to do, and is echoing out pure html.

 

Javascript is client side. You cannot do server side stuff with javascript (but you can with AJAX)

Link to comment
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.