Jump to content
php.lv forumi

Scripts kas attīra MySQL datus


Recommended Posts

Posted (edited)

Sveiki !

 

Mēģinu uztaisīt scriptu , kas attīra vecos datus mysql

 

Lūk mans scripts

 

clean.php -- Šim scriptam doma ir tāda kad ieejot http:/host.lv/clean.php viņš paņem un izdzēš ierakstu kuram datums ir notecējis

<?

include('config.php');

$result = mysql_query("SELECT * FROM `roots22` WHERE (`expire` > 0) AND (UNIX_TIMESTAMP() > `expire`)");
while($row = mysql_fetch_assoc($result));
{
mysql_query('DELETE FROM `adds` WHERE `id` = '.$row['id']);
} 




?>

 

Mysql db

 

CREATE TABLE IF NOT EXISTS `adds` (
 `id` int(11) NOT NULL auto_increment,
 `descr` text NOT NULL,
 `price` float NOT NULL default '0',
 `curr` int(11) NOT NULL default '0',
 `img1` tinytext NOT NULL,
 `l1` int(11) NOT NULL default '0',
 `l2` int(11) NOT NULL default '0',
 `l3` int(11) NOT NULL default '0',
 `l4` int(11) NOT NULL default '0',
 `dat` datetime NOT NULL default '0000-00-00 00:00:00',
 `name` tinytext NOT NULL,
 `phone` tinytext NOT NULL,
 `email` tinytext NOT NULL,
 `site` tinytext NOT NULL,
 `pass` tinytext NOT NULL,
 `deal` int(11) NOT NULL default '0',
 `logo` tinytext NOT NULL,
 `highlight` tinyint(4) NOT NULL default '0',
 `video` tinytext NOT NULL,
 `created` datetime NOT NULL default '0000-00-00 00:00:00',
 `phonecode` tinytext NOT NULL,
 `valid` tinyint(4) NOT NULL default '0',
 `param1` tinytext,
 `vip` tinyint(4) default NULL,
 `paramslat` text,
 `paramsrus` text,
 `paramseng` text,
 `rnd` tinyint(4) NOT NULL default '127',
 `sector` int(11) default '0',
 `price1` float NOT NULL default '0',
 `price2` float NOT NULL default '0',
 `price3` float NOT NULL default '0',
 `pricetype` int(11) NOT NULL default '0',
 PRIMARY KEY  (`id`),
 KEY `l1` (`l1`,`l2`,`l3`,`l4`),
 KEY `highlight` (`highlight`,`img1`(10),`l1`,`l2`,`l3`),
 KEY `vip` (`vip`,`img1`(10),`l1`,`l2`,`l3`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=9970 ;

 

Config.php

 

<?

$db_name = 'db_name';
$db_user = 'db_user';
$db_pass = 'db_parole';
$hostname = 'localhost';

mysql_connect($hostname, $db_user, $db_pass) or die(mysql_error());
mysql_select_db($db_name) or die(mysql_error());


?>

 

Kur es kļūdijos vai kāds varētu palīdzēt man ar kļūdu kur esmu pieļāvis

 

Jo errors ir

 

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /var/www/clean.php on line 6

Edited by spamof
Posted

Nu acīmredzot ir kāda kļūda kvērijā. Vari darīt tā:

$resut = mysql_query("kvērijs") or die(mysql_error());

 

Piedevām tu rādi mums tabulu adds, bet kļūda notiek SELECT kvērijā, kur tiek izmantota tabula roots22

Posted

Kāpēc vajadzīgs šādi ?

 

while($row = mysql_fetch_assoc($result));

 

Es domāju kad vareetu pameigināt arī šādi !

 

while($row = mysql_fetch($result));

Posted

Kāpēc vajadzīgs šādi ?

 

while($row = mysql_fetch_assoc($result));

 

Es domāju kad vareetu pameigināt arī šādi !

 

while($row = mysql_fetch($result));

Mēģināju pec tava parauga , bet tass pats

Fatal error: Call to undefined function mysql_fetch() in /var/www/clean.php on line 6

Posted

Kāpēc vajadzīgs šādi ?

 

while($row = mysql_fetch_assoc($result));

 

Es domāju kad vareetu pameigināt arī šādi !

 

while($row = mysql_fetch($result));

 

Bāc, un tu vēl piesakies taisīt projektus pa lētu naudu...

Posted (edited)

cik ierakstus atgriež pirmais pieprasījums?

 

 

Viņām itkā vissi vecie jaatīra , bet cik es skatos

 


INSERT INTO `adds` (`id`, `descr`, `price`, `curr`, `img1`, `img2`, `img3`, `img4`, `img5`, `img6`, `img7`, `img8`, `img9`, `img10`, `img11`, `img12`, `img13`, `img14`, `img15`, `img16`, `l1`, `l2`, `l3`, `l4`, `dat`, `name`, `phone`, `email`, `site`, `pass`, `deal`, `new`, `guarantee`, `leasing`, `logo`, `highlight`, `video`, `created`, `phonecode`, `valid`, `param1`, `vip`, `paramslat`, `paramsrus`, `paramseng`, `rnd`, `sector`, `price1`, `price2`, `price3`, `pricetype`) VALUES
(491, 'Fm spelites', 50, 0, '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', 4, 81, 356, 0, '2009-11-07 00:31:48', '', 'nr.tel', '', '', 'pDYPEQ', 0, 0, 0, 0, '', 0, '', '2009-10-24 00:31:48', '371', '', '', 0, '', NULL, 'kam speles', '?›?°?‚?‹??????¸?¹, ? ???????¸?¹, ?”?½?¸ ?€?°?±?¾?‚?‹: ???¼?µ???°?½?½?‹?µ', 'Latvian, Russian, Working days:  Mixed', 127, 1560, 50, 50, 50, 0);

 

Man nemazam nav expire :S , bet kā lai uztaisu ,lai viņš izmanto clean.php izmanto "dat" un "created"

 

Vai arī kāds varētu pateikt kā

 

šeit

       mq("insert into adds (param1, descr,price,curr,img1,img2,img3,img4,img5,img6,img7,img8,img9,img10,img11,img12,img13,img14,img15,img16,l1,l2,l3,l4,dat, name, phone, email, site, pass, deal, logo, new, guarantee, leasing, video, created, phonecode, sector, price1, price2, price3, ) values ('$param1', '$_POST[descr]','$_POST[price]','$_POST[curr]','$img1','$img2','$img3','$img4','$img5','$img6','$img7','$img8','$img9','$img10','$img11','$img12','$img13','$img14','$img15','$img16','$_POST[l1]','$_POST[l2]','$_POST[l3]','$_POST[l4]',date_add(now(), interval $_POST[publishfor]),'$_POST[name]','$_POST[phone]','$_POST[email]','$_POST[site]','".pass()."','$_POST[deal]','$logo','$_POST[new]','$_POST[guarantee]','$_POST[leasing]','$video',now(),'$_POST[phonecode]','".(@$_POST["param"]["497"])."','$price1','$price2','$price3')");        

Lai iekļauju

		$time = 
		expire
		'".$u."', UNIX_TIMESTAMP() + '".(86400 * $days)."'

Edited by spamof
Posted

Kāpēc vajadzīgs šādi ?

 

while($row = mysql_fetch_assoc($result));

 

Es domāju kad vareetu pameigināt arī šādi !

 

while($row = mysql_fetch($result));

Bāc, un tu vēl piesakies taisīt projektus pa lētu naudu...

+1

Posted

mysql var dzēst arī joinojot tabulas.

Nav jāselekto visi dzēšamie dati un tad ciklā jāiet cauri un jāsūta n-tie kveriju.

Visu varr izdarīt ar vienu kveriju:

 

DELETE adds FROM adds,roots22 as r WHERE adds.id=r.id and (r.expire>0) and (UNIX_TIMESTAMP() > r.expire)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...