Low cost ecommerce web development India flash website design

Class Insert ID


To use this functionality in our MySQLResult class, add the following method:
File: Database/MySQL.php (in SPLIB) (excerpt)
/**
* Returns the ID of the last row inserted
* @return int
* @access public
*/
function insertID()
{
return mysql_insert_id($this->mysql->dbConn);
}

As you might guess, using this method is quite straightforward:
File: 18.php (excerpt)
// Include the MySQL class
require_once 'Database/MySQL.php';
$host = 'localhost'; // Hostname of MySQL server
$dbUser = 'harryf'; // Username for MySQL
$dbPass = 'secret'; // Password for user
$dbName = 'sitepoint'; // Database name
$db = &new MySQL($host, $dbUser, $dbPass, $dbName);
// 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'";
$result = $db->query($sql);
echo 'The new row as ID: ' . $result->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