Is there a cursor in the mysql database?-php Tutorial

Source: Internet
Author: User
Tags tmp folder
Excuse me: is there a cursor in the mysql database? eldest brother, I want to create a php file, access this php file once, retrieve a record from the database, access the file for the second time, and retrieve the next one,

How can we achieve this? How to use a cursor ,? I don't know how to write SQL statements. thank you.


Reply to discussion (solution)

You do not need to use a MYSQL cursor to access the record set one by one in PHP.

Use the limit clause to specify

Use $ query = "select * from cmsecms_custinfo LIMIT 1"; to obtain a record. for the second time, add a variable.
$ Query = "select * from cmsecms_custinfo LIMIT $ ddd, 1"; $ ddd = $ ddd + 1; and so on? Thank you.

Use $ query = "select * from cmsecms_custinfo LIMIT 1"; to obtain a record. for the second time, add a variable.
$ Query = "select * from cmsecms_custinfo LIMIT $ ddd, 1"; $ ddd = $ ddd + 1; and so on? Thank you.



$ Offset = 10; // offset value
$ Limit = 1; // The number of limit entries.
$ Query = "select * from cmsecms_custinfo LIMIT $ offset, $ limit"

For example, obtain the 11-15 records.
$ Query = "select * from cmsecms_custinfo LIMIT 10, 5"

Yes. you need to add a variable.
And the variable is independent of the program. It can be passed through url or saved in session

Upstairs, I use static variables,
Static $ cursor = 0;
$ Query = "select id, title, email from cmsecms_custinfo where id> '$ cursor 'limit 1 ";
$ Cursor = $ cursor + 1;
$ SQL = $ empire-> query ($ query );

But when the PHP page is refreshed every time, $ cursor is still 0, that is, the first record is obtained. how do I use static variables or global variables?

I don't know how to use the session. thank you.

So I said, "this variable is program-independent"
Static variables exist in the program.

One solution for using session is

session();if(! $_SESSION['cursor'])) $_SESSION['cursor'] = 0;$_SESSION['cursor']++;$cursor = $_SESSION['cursor'];$query="select id,title,email from cmsecms_custinfo LIMIT $cursor";

Upstairs, I use static variables,
Static $ cursor = 0;
$ Query = "select id, title, email from cmsecms_custinfo where id> '$ cursor 'limit 1 ";
$ Cursor = $ cursor + 1;
$ SQL = $ empire-> query ($ query );

But when the PHP page is refreshed every time, $ cursor is still 0, that is, the first record is obtained. how do I use static variables or global variables?

I don't know how to use the session. thank you.



Who told you that static variable refresh will be retained ...?

Session, I will provide an example for your reference.
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);

Slide your hand.
It should be like this:

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

Let me try it. I have a question: Can I refresh the PHP file on the same terminal to automatically retrieve the next one? can different terminals achieve this?

Is this session a server or a local server? Let me try it first.

Appears:
PHP Warning: session_start (): open (/tmp \ logs, 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 that the current setting of session. save_path is correct (/tmp) in Unknown on line 0

Using session is self-changed by various terminals
If you want the effect to be on all terminals, you need to save the variables in the database, File, shared memory, and so on.

Appears:
PHP Warning: session_start (): open (/tmp \ logs, 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 that the current setting of session. save_path is correct (/tmp) in Unknown on line 0


The solution is as follows:
1. after D: \ inetpub \ CMS7, create a tmp folder, that is, D: \ inetpub \ CMS7 \ tmp.
2. change session. save_path = "/tmp" of php. ini to session. save_path = "D: \ inetpub \ CMS7 \ tmp"
3. restart the service

I changed all PHP. INI, restarted the service, and got the same error. it's strange,
I will first try to save the variables in the database, File, shared memory, and so on. I don't know which one is simpler.

I changed all PHP. INI, restarted the service, and got the same error. it's strange,
I will first try to save the variables in the database, File, shared memory, and so on. I don't know which one is simpler.



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

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

Daxia, I think the shared memory function can work normally only when php is an ISAPI running mode in windows. what should I add when installing php? Enable-shmop ., How can I check whether PHP supports shared memory?

Okay, there are still few File Problems. thank you, Big Brother.

Sessions are good, but files are not good, because files are shared by all users. When accessed by different users. For example, if A accesses 10 times and B accesses the data, the data is displayed from 11 records.
Configure the server session. This is just a saving idea, so we can use a prototype to describe it.
You cannot use a file, not a trap.

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.