Jumat, 25 Juni 2010

MySql Fetch Array

Buzz It
MySql Fetch Array

MySql Fetch Array

mysql_affected_rows — Get 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);

Sumber : Materi Kuliah Pemrograman Web | Download Article



Tidak ada komentar:

Posting Komentar