MYSQLI custom input query
I am using mysqli class at one of my project, i want yours help with following...
How to insert custom insert query like we do in mysql
INSERT INTO payment_slip VALUES(NULL, md5(code), 'ABC', 'tester', NOW());
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.
精彩评论