Tag Archives: mysql

Правилно Записване на ipaddress v4 в mysql && php

Тип в MySQL:

INT(11) UNSIGNED

Функции за работа от MySQL

INET_ATON и INET_NTOA

Пример:
query : select INET_ATON('127.0.0.1');
result: 2130706433
query : select INET_NTOA('2130706433');
result: 127.0.0.1

Функции за работа с php
ip2long() и long2ip()

Правят същите неща като тези в MySQL, т.е.:

ip2long($arg) -> INET_ATON('$arg')
long2ip($arg) -> INET_NTOA('$arg')

VN:F [1.9.22_1171]
Rating: 5.0/5 (1 vote cast)
VN:F [1.9.22_1171]
Rating: +1 (from 1 vote)

Изтриване на всички постове от WordPress през MySQL

#Листва постовете от категория 2

SELECT * FROM TABLE_PREFIX_posts p
JOIN TABLE_PREFIX_term_relationships r ON p.ID = r.object_id
JOIN TABLE_PREFIX_term_taxonomy tt ON r.term_taxonomy_id = tt.term_taxonomy_id
JOIN TABLE_PREFIX_term_taxonomy t ON tt.term_id = t.term_id
WHERE t.term_id = 2;

#Листва всички постове

SELECT * FROM TABLE_PREFIX_posts p
JOIN TABLE_PREFIX_term_relationships r ON p.ID = r.object_id
JOIN TABLE_PREFIX_term_taxonomy tt ON r.term_taxonomy_id = tt.term_taxonomy_id
JOIN TABLE_PREFIX_term_taxonomy t ON tt.term_id = t.term_id;

#Изтрива постовете от категория 36
delete a,b,c,d
FROM TABLE_PREFIX_posts a
LEFT JOIN TABLE_PREFIX_term_relationships b ON ( a.ID = b.object_id )
LEFT JOIN TABLE_PREFIX_postmeta c ON ( a.ID = c.post_id )
LEFT JOIN TABLE_PREFIX_term_taxonomy d ON ( d.term_taxonomy_id = b.term_taxonomy_id )
LEFT JOIN TABLE_PREFIX_terms e ON ( e.term_id = d.term_id )
WHERE e.term_id =36;

 

#Изтрива всички постове
delete a,b,c,d
FROM TABLE_PREFIX_posts a
LEFT JOIN TABLE_PREFIX_term_relationships b ON ( a.ID = b.object_id )
LEFT JOIN TABLE_PREFIX_postmeta c ON ( a.ID = c.post_id )
LEFT JOIN TABLE_PREFIX_term_taxonomy d ON ( d.term_taxonomy_id = b.term_taxonomy_id )
LEFT JOIN TABLE_PREFIX_terms e ON ( e.term_id = d.term_id );

VN:F [1.9.22_1171]
Rating: 5.0/5 (1 vote cast)
VN:F [1.9.22_1171]
Rating: +1 (from 1 vote)

Добавяне на администратор в WordPress от MySQL

#Добавяне на тестов администратор

INSERT INTO `TABLE_PREFIX_users` (`ID`, `user_login`, `user_pass`, `user_nicename`, `user_email`, `user_url`, `user_registered`, `user_activation_key`, `user_status`, `display_name`) VALUES ('99999', 'martinwpmartin', md5('superparola'), 'Martin Petrov', 'martin@dhstudio.bg', 'http://mpetrov.net', '2014-04-04 00:00:00', ", '0', 'Martin Petrov');

INSERT INTO `TABLE_PREFIX_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (NULL, '99999', 'TABLE_PREFIX_capabilities', 'a:1:{s:13:"administrator";s:1:"1";}');

INSERT INTO `TABLE_PREFIX_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (NULL, '99999', 'TABLE_PREFIX_user_level', '10');

#Изтриване на тестовия администратор

delete from `TABLE_PREFIX_users` where ID='99999';
delete from `TABLE_PREFIX_usermeta` where user_id='99999';

VN:F [1.9.22_1171]
Rating: 5.0/5 (1 vote cast)
VN:F [1.9.22_1171]
Rating: +1 (from 1 vote)