0

I checked in my database and the view is created with the expected structure but it's empty, there are no rows.

$view= $connexion->prepare("CREATE VIEW MP1 AS SELECT * FROM occupation_data WHERE onetsoc_code IN (".implode(',',$tupleasup).")");

Here what my array look for :

$tupleasup= array('19-1041.00','19-1042.00');

The only thing "weird" that I used is this : How to use php array with sql IN operator?

Thank you

Community
  • 1
  • 1
goldiman
  • 189
  • 2
  • 13
  • 1
    And how does the view look after the php processing? – jarlh May 18 '15 at 13:17
  • It has the expected structure with all the good columns but it's empty – goldiman May 18 '15 at 13:18
  • any errors? checking for them? which MySQL API are you using to connect with? etc.? seems you've a syntax error and not checking for them. http://php.net/manual/en/mysqli.error.php on the query if using `mysqli_`. Hard to say if you're using that or PDO `setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION)` – Funk Forty Niner May 18 '15 at 13:21

2 Answers2

2

Your implode should look like this:

$view= $connexion->prepare("CREATE VIEW MP1 AS SELECT * FROM occupation_data WHERE onetsoc_code IN ('".implode("','",$tupleasup)."')");

(every item should be wrapped up in quotes)

n-dru
  • 9,285
  • 2
  • 29
  • 42
1

You forgot to start and end the single quote '

$view= $connexion->prepare("CREATE VIEW MP1 AS SELECT * FROM occupation_data WHERE onetsoc_code IN ('".implode('\',\'',$tupleasup)."')");

If you echo your query it will be something like this

 CREATE VIEW MP1 AS SELECT * FROM occupation_data WHERE onetsoc_code IN (date1','date2);

which is a wrong syntax so i added single quotes to complete your query

Aman Rawat
  • 2,625
  • 1
  • 25
  • 40