Excuse me: Is there a cursor in the MySQL database?

Source: Internet
Author: User
Tags tmp folder
Brother, I want to make a PHP file, access to this PHP file, from the database to take a record, a second visit, remove a bar,

How can it be achieved? How does a cursor work? SQL statements are less likely to be written. Thank you.


Reply to discussion (solution)

This does not need to use the cursor inside MySQL, in PHP to implement a record set of one-by-one access to the line.

Use the limit clause to specify

Use $query= "SELECT * from Cmsecms_custinfo LIMIT 1"; Get a record, the second time or this record, is not to add a variable
$query = "SELECT * from Cmsecms_custinfo LIMIT $ddd, 1"; $DDD = $ddd +1; Or something like that? Thank you

Use $query= "SELECT * from Cmsecms_custinfo LIMIT 1"; Get a record, the second time or this record, is not to add a variable
$query = "SELECT * from Cmsecms_custinfo LIMIT $ddd, 1"; $DDD = $ddd +1; Or something like that? Thank you



$offset = 10; Offset value
$limit = 1; How many bars are taken?
$query = "SELECT * from Cmsecms_custinfo LIMIT $offset, $limit"

For example, get the 第11-15条 record.
$query = "SELECT * from Cmsecms_custinfo LIMIT 10, 5"

Yes, we need to add a variable.
And this variable is independent of the program. Can be passed by URL or saved in session

Brother Upstairs, I'm using a static variable,
static $cursor = 0;
$query = "Select Id,title,email from Cmsecms_custinfo where id> ' $cursor ' LIMIT 1";
$cursor = $cursor +1;
$sql = $empire->query ($query);

But every time the PHP page refreshes, $cursor or 0, or get the first record, how to use static variables, or global variables?

Don't know how to use the session, thank you.

So I said, "This variable is independent of the program."
Static variables are present in the program.

One scenario for using the session is

session (); if (! $_session[' cursor ')) $_session[' cursor '] = 0;$_session[' cursor ']++; $cursor = $_session[' cursor '];$ query= "Select Id,title,email from Cmsecms_custinfo LIMIT $cursor";

Brother Upstairs, I'm using a static variable,
static $cursor = 0;
$query = "Select Id,title,email from Cmsecms_custinfo where id> ' $cursor ' LIMIT 1";
$cursor = $cursor +1;
$sql = $empire->query ($query);

But every time the PHP page refreshes, $cursor or 0, or get the first record, how to use static variables, or global variables?

Don't know how to use the session, thank you.



Who told you that static variable refreshes would persist ...?

I provide an example for you to refer to the session.
Session_Start (); if (!issert ($_session[' cursor ")) {    $_session[' cursor '] = 0;} else{    $_session[' cursor '] + +;} $cursor = $_session[' cursor ']; $query = "Select Id,title,email from Cmsecms_custinfo where LIMIT $cursor, 1"; $sql = $empire- >query ($query);

The hand slipped a bit.
This should be the case:

Session_Start (); if (!isset ($_session[' cursor ")) {//changed here.    $_session[' cursor '] = 0;} else{    $_session[' cursor '] + +;} $cursor = $_session[' cursor ']; $query = "Select Id,title,email from Cmsecms_custinfo where LIMIT $cursor, 1 "; $sql = $empire->query ($query);

Ok I try, there is a question: the same terminal refresh this PHP, can be implemented automatically remove a message, different terminals can be implemented?

Is this session a server or a local? I'll try it first.

Appear:
PHP Warning:session_start (): Open (/tmp\sess_usuklqaaeh5j7tmrfh04vv9a54, O_RDWR) failed:no such file or directory (2) in D:\inetpub\CMS7\e\admin\ListOneInfo.php on line 46
PHP Warning:Unknown:open (/tmp\sess_usuklqaaeh5j7tmrfh04vv9a54, O_RDWR) failed:no such file or directory (2) in Unknown On line 0
PHP Warning:Unknown:Failed to write session data (files). Please verify this current setting of Session.save_path is correct (/tmp) in Unknown on line 0

Use session This is the individual terminal self-change
If you want the effect to be the same for all terminals, you need to save the variable in the database, file, shared memory, etc.

Appear:
PHP Warning:session_start (): Open (/tmp\sess_usuklqaaeh5j7tmrfh04vv9a54, O_RDWR) failed:no such file or directory (2) in D:\inetpub\CMS7\e\admin\ListOneInfo.php on line 46
PHP Warning:Unknown:open (/tmp\sess_usuklqaaeh5j7tmrfh04vv9a54, O_RDWR) failed:no such file or directory (2) in Unknown On line 0
PHP Warning:Unknown:Failed to write session data (files). Please verify this current setting of Session.save_path is correct (/tmp) in Unknown on line 0


Because you are a Windows system, there is no/tmp, the workaround is as follows:
1. After D:\inetpub\CMS7, create a TMP folder that is D:\inetpub\CMS7\tmp
2. Change PHP.ini's Session.save_path = "/tmp" to Session.save_path = "D:\inetpub\CMS7\tmp"
3. Restart the service

Change all the php.ini, restart the service, there is the same mistake, strange,
I'm going to try. Save variables in database, file, shared memory and so on, don't know which is simpler

Change all the php.ini, restart the service, there is the same mistake, strange,
I'm going to try. Save variables in database, file, shared memory and so on, don't know which is simpler



That is your server is not configured, if the first test, you can write the variable file it.

$file = ' session.txt ';
if (!file_exists ($file)) {
$cursor = 0;
File_put_contents ($file, 0, true);
}else{
$cursor = file_get_contents ($file);
$cursor + +;
File_put_contents ($file, $cursor, true);
}

$query = "Select Id,title,email from Cmsecms_custinfo where LIMIT $cursor, 1";
$sql = $empire->query ($query);

Warrior, I look at the function of shared memory, but also to see in Windows only when PHP is the ISAPI operation mode to work properly, when installing PHP to add the ENABLE-SHMOP. , how do you see if PHP supports shared memory?

Good, or file problem less, thank you brother

Use the session well, with the file is not good, because the file is shared by all users. When different users access it. For example, a visits 10 times, then B accesses, and then the 11 records start to show.
Configure the server with the session bar. Just to provide the idea of saving, so you can use the document to do a prototype to illustrate.
It's not good to use a file, it's not a pit.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.