0

I have an SQL query that i run on the database manually which checks the catalogue for products that do not have an image and hides them, i want to run this via cron so have created a php with the following content:

    <?php 

$servername = "localhost";
$username = "xxx";
$password = "xxx";
$dbname = "xxx";

// Create connection
$conn = new mysqli($servername, $username, $password,$dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

// Script to run

$sql= 

update catalog_product_entity_int m;
left join eav_attribute a on a.entity_type_id = 4 and a.attribute_id = m.attribute_id
set value = 2
where
a.attribute_code = 'status'
and m.entity_id in
(
select m.entity_id
from catalog_product_entity m
left join catalog_product_entity_media_gallery_value_to_entity a
on a.entity_id = m.entity_id
where a.value_id is null
)
;

if ($conn->query($sql) === TRUE) {
    echo "Record updated successfully";
} else {
    echo "Error updating record: " . $conn->error;
}

$conn->close();

?>

But I get this error: [PHP Parse error: syntax error, unexpected 'catalog_product_entity_int' (T_STRING) in /home/public_html/modimages/hideimages.php on line 20

The query works fine when i put it directly on phpmyadmin so i am guessing i am missing something very simple.

1

You missed the quotes (") in variable $sql. Try the below one.

$sql= "update catalog_product_entity_int m
left join eav_attribute a on a.entity_type_id = 4 and a.attribute_id = m.attribute_id
set value = 2
where
a.attribute_code = 'status'
and m.entity_id in
(
select m.entity_id
from catalog_product_entity m
left join catalog_product_entity_media_gallery_value_to_entity a
on a.entity_id = m.entity_id
where a.value_id is null
)";
  • Worked perfectly, thank you! – Mehdi Rafiai May 13 at 15:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.