Low cost ecommerce web development India flash website design
When you’re dealing with AUTO_INCREMENT columns in database tables, it’s
often
useful to be able to find out the ID of a row you’ve just inserted, so
that other
tables can be updated with this information. That, after all, is how relationships
between tables are built. PHP provides the function mysql_insert_id, which,
when given a link identifier, returns the ID generated by the last INSERT performed
with that connection. Here’s how mysql_insert_id can be used:
File: 17.php (excerpt)
// A query to insert a row
$sql = "INSERT INTO
articles
SET
title='How to use mysql_insert_id()',
body='This is an example',
author='HarryF'";
// Run the query, identifying the connection
$queryResource = mysql_query($sql, $dbConn);
// Fetch the inserted ID
$insertID = mysql_insert_id($dbConn);
echo 'The new row has ID: ' . $insertID;
website designer freelance ASP PHP ecommerce web developer
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110