Minggu, 13 November 2011

MySQL Fetch Array

mysql_affected_rowsGet number of affected rows in previous MySQL operation.

code

<?php
$link = mysql_connect('localhost', 'root', '');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db('sarwojowo');

/* this should return the correct numbers of deleted records */
mysql_query('DELETE FROM student  WHERE id < 5');
printf("Records deleted: %d\n", mysql_affected_rows());

?>

before please create database with name sarwojowo
and create table with structure below  :

Table

CREATE TABLE `student` (
`id` int(2) NOT NULL auto_increment,
`name` varchar(50) collate latin1_general_ci NOT NULL default '',
`class` varchar(10) collate latin1_general_ci NOT NULL default '',
`mark` int(3) NOT NULL default '0',
UNIQUE KEY `id` (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=57 ;

--
-- Dumping data for table `student_adv`
--

INSERT INTO `student` VALUES (5, 'John Mike', 'Four', 60);
INSERT INTO `student` VALUES (6, 'Alex John', 'Four', 55);
INSERT INTO `student` VALUES (7, 'My John Rob', 'Fifth', 78);

Tidak ada komentar:

Posting Komentar