Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Apr 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Queries execute via phpmyadmin but not via php script

    Hello, I'm brand new with mysql and I encountered the following problem - I've got 2 mysql queries below and I try to execute them via php script but syntax error appears. When I execute them via phpmyadmin it works like a charm showing proper results. I tried with separator to do multiple queries in one execution, but it didn't work. Do you have any ideas?

    PHP Code:
    DELETE a FROM wp_posts AS a INNER JOIN SELECT post_contentMINid ) AS min_id FROM wp_posts WHERE post_type 'post' AND post_status 'publish' GROUP BY post_content HAVING COUNT( * ) > ) AS b ON b.post_content a.post_content AND b.min_id <> a.id AND a.post_type 'post' AND a.post_status 'publish';

    DELETE FROM wp_posts

    WHERE post_content NOT LIKE 
    '%<img src=%'AND ID not in (select post_id as p from wp_postmeta where meta_key like '_wp_attached_file')

    OR `
    post_titlelike '%.png%'

    OR post_date DATE_SUB(NOW(), INTERVAL 15 day); 

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,211
    Thanks
    23
    Thanked 605 Times in 604 Posts
    <?php
    /* First open connection */
    $DBhost = "localhost";
    $username = "my_user";
    $password = "my_password";
    $database = "world";
    $mysqli = new mysqli($DBhost,$username,$password,$database);

    /* Then form the query */
    $query = "DELETE a FROM wp_posts
    AS a INNER JOIN ( SELECT post_content, MIN( id ) AS min_id FROM wp_posts
    WHERE post_type = 'post'
    AND post_status = 'publish'
    GROUP BY post_content
    HAVING COUNT( * ) > 1 )
    AS b ON b.post_content = a.post_content
    AND b.min_id <> a.id
    AND a.post_type = 'post'
    AND a.post_status = 'publish'";

    /* Then exicute the query */
    $results = mysqli_query($query);



    $query = "DELETE FROM wp_posts
    WHERE post_content NOT LIKE '%<img src=%'
    AND ID not in (select post_id as p from wp_postmeta where meta_key like '_wp_attached_file')
    OR `post_title` like '%.png%'
    OR post_date < DATE_SUB(NOW(), INTERVAL 15 day)";
    $results = mysqli_query($query);
    ?>
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •