开发者

MYSQLI custom input query

I am using mysqli class at one of my project, i want yours help with following...

  1. How to insert custom insert query like we do in mysql

    INSERT INTO payment_slip VALUES(NULL, md5(code), 'ABC', 'tester', NOW());

  2. How to get last insert id using this cl开发者_StackOverflowass.

Providing methods would be great help, thanks.


Just like the plain old mysql functions mysqli has a field for this too:

mysqli->insert_id

From php docs (note that this only demonstrates getting the ID, the parameters are hardcoded into the query):

$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

$query = "INSERT INTO payment_slip VALUES(NULL, md5(code), 'ABC', 'tester', NOW())";
$mysqli->query($query);
printf ("New Record has id %d.\n", $mysqli->insert_id);


Running mysqli_insert_id() will also work, but you should use it like vbence said.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜