2013-04-19 22:23

Android和MySQL:获取mysql_insert_id()并在Android Activity中检索它

  • android
  • php

Hi I have connected a MySQL in a server with and Android application using JSON. I have a table called products where the primary key is and id which is auto_increment. When I insert a new product I would like to get that Id in my android Activity but I don't know how to retrieve it in PHP nor Android. Here is some code: Create Product Script

if (isset($_POST['name']) && isset($_POST['price']) && isset($_POST['description'])) {

    $name = $_POST['name'];
    $price = $_POST['price'];
    $description = $_POST['description'];

    // include db connect class
    require_once __DIR__ . '/db_connect.php';

    // connecting to db
    $db = new DB_CONNECT();

    // mysql inserting a new row
    $result = mysql_query("INSERT INTO products(name, price, description) VALUES('$name', '$price', '$description')");

Where should I put mysql_insert_id() ?

Finally, how could I get that mysql_insert_id() in my android activity?

Thanks in advance

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享