RSS   Twitter   Copiny   Copiny
Нашел ошибку? 

Выдели фрагмент текста с ошибкой или неточностью и нажми Ctrl+Enter!

Выполнение запросов к базе данных

Из всего разнообразия методов класса JDatabase самым основным является query(). Он выполняет запросы напрямую в базу данных, без дополнительных вмешательств со стороны Joomla.

Обычная функция PHP mysql_query обычно вернет ссылку на ресурс, который потом с помощью нескольких действий можно преобразовать в нормальный ответ в виде ассоциативного массива. Метод query(), в отличие от функций PHP, вернет булево значение, по которому можно понять выполнился запрос или нет. Обычно его используют в следующих типах запросов:

  • DELETE
  • INSERT
  • RENAME
  • REPLACE
  • UPDATE

Хотя никто не запрещает писать там что-нибудь и посложнее. Разберем выше сказанное на практике. Попробуем к примеру выполнить запрос, который удаляет из таблицы «#__mycomponent_foobars» все записи, где ordering больше 4.



// берем ссылку на объект базы данных
$db =& JFactory::getDBO();
 
// подготовка имен
$tableName  = $db->nameQuote('#__mycomponent_foobars');
$columnName = $db->nameQuote('ordering');
 
// строим SQL
$sql = "DELETE FROM $tableName WHERE $columnName > 4 ";
 
// предварительно устанавливаем текст запроса 
$db->setQuery($sql);
 
// выполняем запрос и в зависимости от ответа выполняем соответствующее действие
if ($db->query()) {
    // успешно выполнился
} else {
    // неудача (например, ошибка в синтаксисе SQL)
}

Так, как в случае неудачи мы получим FALSE, то после проверки запроса можно сделать вывод ошибок, например в log-файл.

Очень полезным может оказаться метод JDatabase::getAffectedRows(), который вернет количество строк, к которым был применен последний запрос. Используется следующим образом:


// в случае успеха
$affectRowCount = $db->getAffectedRows();
 
// выводим сообщение
echo JText::sprintf('DELETED %u RECORDS', $affectRowCount);

Смотрите также:
Комментарии (69) Добавить комментарий
  • Сергей
    Сергей
    03 Ноября 2012, 19:33
     ↑  0  ↓     ответ

    т.е получается что по ссылке запустится модуль, а модуль снова вернет нас к ссылке?

  • tinyurl.com
    tinyurl.com
    23 Ноября 2019, 22:18
     ↑  0  ↓     ответ

    You are so cool! I do not suppose I have read anything

    like this before. So nice to find someone with a few genuine thoughts on this subject.

    Seriously.. thanks for starting this up. This site is one thing that's needed on the web, someone with a little originality!

  • tinyurl.com
    tinyurl.com
    24 Ноября 2019, 19:12
     ↑  0  ↓     ответ

    Hello i am kavin, its my first occasion to commenting

    anyplace, when i read this paragraph i thought i could also create comment due to

    this sensible piece of writing.

  • coconut oil a
    coconut oil a
    25 Ноября 2019, 15:16
     ↑  0  ↓     ответ

    My partner and I stumbled over here from a different

    page and thought I might as well check things out.

    I like what I see so now i'm following you. Look forward

    to checking out your web page for a second time.

  • plenty of fish dating site
    plenty of fish dating site
    27 Ноября 2019, 03:31
     ↑  0  ↓     ответ

    Quality articles or reviews is the main to

    invite the viewers to visit the site, that's what this website is providing.

  • g
    g
    16 Июня 2020, 11:55
     ↑  0  ↓     ответ

    What's up, yup this post is truly pleasant and I have learned lot

    of things from it regarding blogging. thanks.

  • g
    g
    17 Июня 2020, 12:55
     ↑  0  ↓     ответ

    I think everything composed was very logical. But, what about this?

    suppose you typed a catchier post title?

    I mean, I don't want to tell you how to run your blog, but suppose you added a

    title that makes people want more? I mean Выполнение запросов к базе данных / Работа с базой данных .:.

    Документация Joomla! CMS is a little boring.

    You ought to look at Yahoo's front page and see how they write post headlines

    to grab viewers to open the links. You might add a

    video or a pic or two to get readers excited about

    everything've written. In my opinion, it could bring your posts a little livelier.

  • g
    g
    17 Июня 2020, 16:53
     ↑  0  ↓     ответ

    naturally like your web site however you need to check the spelling on several of your posts.

    A number of them are rife with spelling issues and I find it very

    bothersome to tell the truth then again I'll surely

    come back again.

  • cheap flights
    cheap flights
    29 Января 2021, 15:57
     ↑  0  ↓     ответ

    Hi there to all, how is everything, I think every one is getting more

    from this web site, and your views are pleasant designed for new people.

  • cheap flights
    cheap flights
    29 Января 2021, 17:19
     ↑  0  ↓     ответ

    What's up everyone, it's my first pay a quick visit at this

    website, and post is really fruitful designed for me,

    keep up posting these types of posts.

  • cheap flights
    cheap flights
    30 Января 2021, 12:12
     ↑  0  ↓     ответ

    Thanks , I have just been looking for info approximately this topic for a while and yours is the

    greatest I have discovered till now. However, what about the conclusion? Are you certain in regards to

    the source?

  • https://bestrajusmia1984.netlify.app
    https://bestrajusmia1984.netlify.app
    17 Февраля 2021, 08:02
     ↑  0  ↓     ответ

    Master The Curriculum Time Difference Between Feet And Meter In Poetry

  • inbooks.atthost24.pl
    inbooks.atthost24.pl
    30 Марта 2021, 23:29
     ↑  0  ↓     ответ

    Froebel Public School Cutting For Stone Genre

  • http://inbooks.atthost24.pl/
    http://inbooks.atthost24.pl/
    31 Марта 2021, 17:07
     ↑  0  ↓     ответ

    English Language And Literature Journal Super Teacher Reading Comprehension

  • polandsleep.e-kei.pl
    polandsleep.e-kei.pl
    01 Апреля 2021, 08:38
     ↑  0  ↓     ответ

    Physics For Scientists And Engineers Review To Kill A Mockingbird Litcharts Chapter 13

  • read online
    read online
    01 Апреля 2021, 18:54
     ↑  0  ↓     ответ

    Polytechnic Admission Test 2019 Assam Emotional Intelligence 2.0 Self Management Strategies

  • http://baringbooker.nstrefa.pl/cmilumbhyl
    http://baringbooker.nstrefa.pl/cmilumbhyl
    02 Апреля 2021, 19:22
     ↑  0  ↓     ответ

    Octavia Butler Net Worth Free Audio Books Online Download Harry Potter

  • 0mniartist
    0mniartist
    08 Апреля 2021, 12:42
     ↑  0  ↓     ответ

    Wow! This blog looks exactly like my old one!

    It's on a entirely different subject but it has

    pretty much the same page layout and design. Outstanding choice of colors!

    0mniartist asmr

  • 0mniartist
    0mniartist
    08 Апреля 2021, 17:40
     ↑  0  ↓     ответ

    Right here is the right webpage for anybody who really wants to understand this topic.

    You understand a whole lot its almost hard to argue with you (not that

    I really would want to…HaHa). You definitely put a new spin on a topic which has been discussed for ages.

    Excellent stuff, just wonderful! asmr 0mniartist

  • 0mniartist
    0mniartist
    09 Апреля 2021, 03:18
     ↑  0  ↓     ответ

    Very descriptive article, I enjoyed that bit. Will there be a part

    2? asmr 0mniartist

  • 0mniartist
    0mniartist
    09 Апреля 2021, 09:48
     ↑  0  ↓     ответ

    Keep this going please, great job! asmr 0mniartist

  • 0mniartist
    0mniartist
    10 Апреля 2021, 00:26
     ↑  0  ↓     ответ

    whoah this weblog is excellent i love reading

    your articles. Stay up the good work! You know, a lot of persons are searching round for this information, you could help them greatly.

    0mniartist asmr

  • get pdf
    get pdf
    21 Апреля 2021, 08:07
     ↑  0  ↓     ответ

    Good Books To Read With Your Mom Red White And Royal Blue Review

  • avhamara1977.netlify.app
    avhamara1977.netlify.app
    21 Апреля 2021, 14:51
     ↑  0  ↓     ответ

    Z Words In The Lion The Witch And The Wardrobe

    The Westing Game Jake Wexler

  • kanyon957.blogaaja.fi
    kanyon957.blogaaja.fi
    03 Июля 2021, 21:49
     ↑  0  ↓     ответ

    Interesting Science Articles For Middle School John Green Books

    Online Shopping

  • wordpress.org
    wordpress.org
    06 Июля 2021, 17:51
     ↑  0  ↓     ответ

    Plato Republic Literature Autobiography Usain Bolt

  • canadian pharmacy cialis 20mg
    canadian pharmacy cialis 20mg
    13 Июля 2021, 14:15
     ↑  0  ↓     ответ

    I enjoy what you guys tend to be up too. This sort of clever work and exposure!

    Keep up the fantastic works guys I've incorporated you guys to my own blogroll.

  • ?????
    ?????
    13 Июля 2021, 15:41
     ↑  0  ↓     ответ

    Wow, great blog article.Really thank you! Really Great.

  • camping supplies
    camping supplies
    30 Июля 2021, 21:37
     ↑  0  ↓     ответ

    cccc nursing application deadline role of teacher

    as a counsellor

    https://100bestczbooks.blogspot.com

    pomona college dorms reddit lava my z customisation

    https://bestczreada.blogspot.com

  • but ps4 games
    but ps4 games
    23 Августа 2021, 05:31
     ↑  0  ↓     ответ

    Wow, amazing weblog format! How lengthy have you ever been running a blog for?

    you make blogging glance easy. The full glance of your website is wonderful, let alone the content material!

  • ps4 games off
    ps4 games off
    23 Августа 2021, 18:10
     ↑  0  ↓     ответ

    I am regular visitor, how are you everybody? This paragraph

    posted at this web page is truly good.

  • tinyurl.com
    tinyurl.com
    21 Марта 2022, 23:44
     ↑  0  ↓     ответ

    Hello my friend! I wish to say that this post

    is amazing, great written and include approximately

    all vital infos. I would like to look more

    posts like this .

  • tinyurl.com
    tinyurl.com
    22 Марта 2022, 16:28
     ↑  0  ↓     ответ

    Hurrah, that's what I was seeking for, what a stuff!

    present here at this web site, thanks admin of this site.

  • tinyurl.com
    tinyurl.com
    22 Марта 2022, 20:45
     ↑  0  ↓     ответ

    Its like you learn my mind! You seem to know so much approximately

    this, like you wrote the e book in it or something.

    I believe that you just could do with a few % to pressure the message house a bit, but other than that, this is magnificent blog.

    An excellent read. I'll certainly be back.

  • http://tinyurl.com
    http://tinyurl.com
    23 Марта 2022, 10:23
     ↑  0  ↓     ответ

    I’m not that much of a online reader to be honest but your

    sites really nice, keep it up! I'll go ahead and bookmark your website to come back later.

    Many thanks

  • http://bit.ly/
    http://bit.ly/
    23 Марта 2022, 23:40
     ↑  0  ↓     ответ

    We are a bunch of volunteers and starting a new scheme

    in our community. Your website provided us with valuable

    info to work on. You have performed a formidable task and our whole community shall be thankful to you.

  • http://tinyurl.com/y7llvdvz
    http://tinyurl.com/y7llvdvz
    24 Марта 2022, 13:21
     ↑  0  ↓     ответ

    It's not my first time to go to see this website, i am visiting

    this website dailly and take pleasant facts from here every day.

  • http://bit.ly
    http://bit.ly
    25 Марта 2022, 01:52
     ↑  0  ↓     ответ

    If some one desires to be updated with hottest technologies afterward he must be go to see this website and be up to date everyday.

  • http://tinyurl.com
    http://tinyurl.com
    28 Марта 2022, 13:19
     ↑  0  ↓     ответ

    I was recommended this website by my cousin. I am not sure whether this post is written by him as nobody else know

    such detailed about my trouble. You are amazing!

    Thanks!

  • http://tinyurl.com
    http://tinyurl.com
    28 Марта 2022, 15:38
     ↑  0  ↓     ответ

    Hello my loved one! I wish to say that this post is amazing, nice written and come

    with approximately all vital infos. I would like to peer more posts like this .

  • cheap flights tickets
    cheap flights tickets
    06 Апреля 2022, 05:25
     ↑  0  ↓     ответ

    This site truly has all the information I needed concerning this

    subject and didn't know who to ask.

  • cheap air tickets
    cheap air tickets
    06 Апреля 2022, 20:10
     ↑  0  ↓     ответ

    You are so interesting! I don't suppose I've read

    through a single thing like this before. So great to

    find someone with genuine thoughts on this subject. Seriously..

    thanks for starting this up. This website is

    something that's needed on the internet, someone with a little originality!

  • gamefly
    gamefly
    07 Апреля 2022, 11:29
     ↑  0  ↓     ответ

    Hello! Do you use Twitter? I'd like to follow you if that would be ok.

    I'm undoubtedly enjoying your blog and look forward to new posts.

  • gamefly
    gamefly
    11 Апреля 2022, 00:35
     ↑  0  ↓     ответ

    You've made some decent points there. I looked

    on the web for more information about the issue and found most individuals

    will go along with your views on this website.

  • http://tinyurl.com/y2lkcqzr
    http://tinyurl.com/y2lkcqzr
    10 Мая 2022, 09:47
     ↑  0  ↓     ответ

    When someone writes an post he/she retains the

    image of a user in his/her mind that how a user can understand it.

    Thus that's why this article is outstdanding.

    Thanks!

  • http://tinyurl.com
    http://tinyurl.com
    12 Мая 2022, 02:56
     ↑  0  ↓     ответ

    Currently it sounds like Movable Type is the top

    blogging platform out there right now. (from what

    I've read) Is that what you are using on your blog?

  • tinyurl.com
    tinyurl.com
    16 Мая 2022, 22:05
     ↑  0  ↓     ответ

    Yes! Finally something about a.

  • t.co
    t.co
    05 Июня 2022, 13:59
     ↑  0  ↓     ответ

    Attractive section of content. I just stumbled upon your weblog and in accession capital

    to assert that I get in fact enjoyed account your blog

    posts. Anyway I will be subscribing to your augment and even I achievement

    you access consistently quickly.

  • tinyurl.com
    tinyurl.com
    07 Июля 2022, 05:56
     ↑  0  ↓     ответ

    Very rapidly this site will be famous amid all blogging

    viewers, due to it's fastidious content

  • tinyurl.com
    tinyurl.com
    12 Июля 2022, 03:37
     ↑  0  ↓     ответ

    Hey! Quick question that's totally off topic. Do you

    know how to make your site mobile friendly? My web site looks weird when viewing from my iphone.

    I'm trying to find a theme or plugin that might be able to correct this

    issue. If you have any recommendations, please share. Thank you!

  • http://bit.ly
    http://bit.ly
    15 Июля 2022, 16:34
     ↑  0  ↓     ответ

    I savour, result in I found exactly what I used to be having

    a look for. You've ended my 4 day long hunt!

    God Bless you man. Have a great day. Bye

  • http://tinyurl.com/29lnxjyl
    http://tinyurl.com/29lnxjyl
    22 Июля 2022, 15:15
     ↑  0  ↓     ответ

    I just could not leave your web site before suggesting that I actually enjoyed the usual info an individual provide for your guests?

    Is gonna be back often to investigate cross-check new posts

  • tinyurl.com
    tinyurl.com
    23 Июля 2022, 08:16
     ↑  0  ↓     ответ

    Link exchange is nothing else but it is simply placing

    the other person's weblog link on your page at appropriate place and other person will also do similar

    in favor of you.

  • tinyurl.com
    tinyurl.com
    26 Июля 2022, 02:23
     ↑  0  ↓     ответ

    WOW just what I was searching for. Came here by searching for or

  • tinyurl.com
    tinyurl.com
    26 Июля 2022, 11:14
     ↑  0  ↓     ответ

    My brother recommended I may like this web site. He was

    once entirely right. This put up actually made my day.

    You cann't believe simply how so much time I had spent for this

    info! Thanks!

  • tinyurl.com
    tinyurl.com
    31 Июля 2022, 18:24
     ↑  0  ↓     ответ

    Quality articles or reviews is the important to attract the viewers to go to

    see the site, that's what this web page is providing.

  • tinyurl.com
    tinyurl.com
    02 Августа 2022, 03:52
     ↑  0  ↓     ответ

    Hey there! Someone in my Facebook group shared this website

    with us so I came to check it out. I'm definitely loving the information. I'm book-marking and will be tweeting this to my followers!

    Terrific blog and amazing design and style.

  • http://tinyurl.com/
    http://tinyurl.com/
    03 Августа 2022, 18:11
     ↑  0  ↓     ответ

    Greetings! I know this is kinda off topic but I was wondering which blog platform are you using for this site?

    I'm getting sick and tired of Wordpress because I've had issues with hackers

    and I'm looking at options for another platform.

    I would be awesome if you could point me in the direction of a good platform.

  • http://www.acedigitech.com
    http://www.acedigitech.com
    07 Августа 2022, 19:07
     ↑  0  ↓     ответ

    Thanks for sharing such a nice opinion, paragraph is nice, thats why i have read

    it entirely

  • tinyurl.com
    tinyurl.com
    08 Августа 2022, 16:28
     ↑  0  ↓     ответ

    Hey there! I just wanted to ask if you ever have any trouble with

    hackers? My last blog (wordpress) was hacked and I ended up

    losing a few months of hard work due to no backup. Do you have any methods to stop hackers?

  • tinyurl.com
    tinyurl.com
    10 Августа 2022, 02:54
     ↑  0  ↓     ответ

    Hello There. I discovered your weblog using msn. That is a really neatly written article.

    I'll be sure to bookmark it and come back to read extra of your useful info.

    Thanks for the post. I'll certainly return.

  • tinyurl.com
    tinyurl.com
    10 Августа 2022, 23:56
     ↑  0  ↓     ответ

    Magnificent beat ! I wish to apprentice even as you

    amend your site, how could i subscribe for a blog web site?

    The account aided me a appropriate deal. I were tiny bit acquainted of

    this your broadcast offered vibrant clear concept

  • 2022
    2022
    12 Августа 2022, 03:31
     ↑  0  ↓     ответ

    I am sure this post has touched all the internet visitors, its

    really really nice article on building up new blog.

  • tinyurl.com
    tinyurl.com
    13 Августа 2022, 17:44
     ↑  0  ↓     ответ

    Hi there! This blog post couldn't be written any better!

    Reading through this post reminds me of my previous roommate!

    He continually kept preaching about this.

    I most certainly will send this post to him. Pretty sure he's going to have

    a great read. I appreciate you for sharing!

  • http://tinyurl.com/
    http://tinyurl.com/
    15 Августа 2022, 05:43
     ↑  0  ↓     ответ

    You could certainly see your enthusiasm within the article you write.

    The sector hopes for even more passionate writers like you who aren't afraid to say how they believe.

    At all times go after your heart.

  • http://tinyurl.com/2pjebzl2
    http://tinyurl.com/2pjebzl2
    17 Августа 2022, 20:52
     ↑  0  ↓     ответ

    You should take part in a contest for one of the highest quality blogs on the net.

    I'm going to highly recommend this site!

  • tinyurl.com
    tinyurl.com
    18 Августа 2022, 20:02
     ↑  0  ↓     ответ

    Incredible story there. What happened after? Good luck!

  • tinyurl.com
    tinyurl.com
    19 Августа 2022, 17:54
     ↑  0  ↓     ответ

    I am no longer positive where you are getting your info, but great topic.

    I needs to spend some time finding out more

    or working out more. Thank you for wonderful info I

    was looking for this info for my mission.

  • tinyurl.com
    tinyurl.com
    21 Августа 2022, 00:40
     ↑  0  ↓     ответ

    I think everything published was very reasonable.

    But, what about this? what if you added a little content?

    I mean, I don't wish to tell you how to run your blog, but what if you added something that grabbed

    people's attention? I mean Выполнение запросов к базе данных / Работа с базой данных .:

    . Документация Joomla! CMS is kinda plain. You ought to peek at Yahoo's

    home page and note how they write post headlines to get viewers to click.

    You might add a related video or a related picture or two

    to get people interested about everything've written. Just my opinion, it would make your

    posts a little bit more interesting.

Оставить комментарий




* обязательно для заполнения

1 введенный почтовый адрес используется только для обратной связи при ответах в комментариях и сервиса gravatar.com
.