1

I am trying to Pull from MySQL but just can't get the string right to pull from the right field.

it is pulling from the wrong location. currently from (catalog_product_entity_media_gallery_value_video) and should be pulling the video from (catalog_product_entity_varchar) (attribute id 147) this gives the value for the correct stored URL in the database. Not sure what is the correct code string.

Here is my code:

$sql = "SELECT url FROM catalog_product_entity_media_gallery_value_video where value_id= ".$product_data['entity_id']." ";
$video_url = $connection->fetchOne($sql);

I am trying this but has to have the 'attribute_id' of 174 included to pull the correct 'value' and get the URL in the database.

Here is my code:

$sql = "SELECT url FROM catalog_product_entity_varchar where value_id= ".$product_data['value']." ";
$video_url = $connection->fetchOne($sql);

any thoughts on how to add the addition of attribute_id of 174 in this string to be able to pull the URL stored in the value field..?

Current code Image

Current Database fields

Thanks PRiZM..

Naeem Khan
  • 950
  • 4
  • 13
  • 34
  • 2
    Strings need to be quoted. Parameterize your query, it will fix both issues. This should be throwing an error message, it is not clear if you are using error reporting, or what driver you use. – user3783243 Feb 21 '19 at 03:38
  • 3
    Possible duplicate of [How can I prevent SQL injection in PHP?](https://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) – user3783243 Feb 21 '19 at 03:38
  • Are you really doing this in `Brightscript` (in other words, are you writing this inside a Roku application) or should that tag not be on this question? – Joe T Feb 21 '19 at 18:25
  • brightscript source connects to this server side php and connects to magento API via JSON – Chris Prizm Feb 22 '19 at 20:07

1 Answers1

0

Skip about SQL Ịnjecttion, let me tell you how you can work with EAV Design in Magento Database.

1: table product_entity you have primary entity_id, and you have entity_type_id = 4 (Product entity type = 4)

2: table eav_attribute with this table you will get attribute_code and attribute_id

3: which catalog_product_entity_varchar you have the value of these attribute have typed is 'text' or 'varchar'.

EAV design

When you need to get the value of a product attribute what you need. 1: attribute_code ==> attribute_id

2: attribute_id => attribute_values

3: product entity_id => value of the attribute of the product

Example SQL:

select v.value from 
    catalog_product_entity_varchar where attribute_id = [attirbute-id] 
    and entity_id = [product entity id]

Update

  • By SQL Injection security you should use $connection->quote([value])

  • You should use the Default Model of Magento to playing with the database.

  • Try to research about getting specific product attribute value.

HoangHieu
  • 2,802
  • 3
  • 28
  • 44