douzhulv1699 2014-09-29 17:35
浏览 3
已采纳

mysql连接如何工作

mysqli_insert_id() is specific to the database connection -- it returns the ID of the row that this script invocation inserted most recently, not any other MySQL client. So there's no conflict if multiple applications are inserting into the database at the same time.

I am confused in 2 things first one is

specific to the database connection

and second thing

MySQL client

Please is there anyone who can explian that how mysql connections work for different clients or how these clients behave in any Application. I am sorry if it is a riddiculous question but i am confused that why it is not reflected by the data entry at the same time.

  • 写回答

1条回答 默认 最新

  • douche1936 2014-09-29 17:54
    关注

    specific to the database connection

    Suppose I run a PHP script that inserts a row, and then calls mysqli_insert_id(), and it tells me it generated value 1234.

    Next, you also run a separate PHP script that inserts a row to the same table. We assume it generated value 1235.

    Then my PHP script, still running in the same request as before, calls mysqli_insert_id() again. Does it report 1235? No -- it still reports 1234, because it will tell me only the most recent id generated during my session.

    If my PHP request finishes, and then I make another PHP request, and it connects to MySQL, this counts as a new connection. Mysqli_insert_id() reports nothing by default, unless I do a new insert.

    MySQL client

    In this context, a mysql client is for example the PHP script that makes a connection to MySQL during one request.

    A MySQL client can also be the command-line mysql tool, or a GUI interface like MySQL Workbench, or another application written in PHP or another language. The term "MySQL client" is meant to include all of these. Each client makes a connection to the MySQL database server, and each connection has its own idea of what the last insert id was.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗