mysql - Select Query returns NULL when using PHP Array -


trying send few file names server via php script ios device using json.

i can send file names , receive them if use:

    $handle = fopen('php://input','r');     $jsoninput = fgets($handle);     $decoded = json_decode($jsoninput,true);      sendresponse(200, json_encode($decoded));  

i sent json string ios like= ["sample.pdf","sample-1.pdf"] sendresponse 200 in ios device proves send , receive methods working=

(     "sample.pdf",     "sample-1.pdf" ) 

however if change code below , try run query query failed

$handle = fopen('php://input','r'); $jsoninput = fgets($handle); $decoded = json_decode($jsoninput,true); var_dump($decoded); $names = join("', '",$decoded); var_dump($names);  $sql = new mysqli($config['localhost'], $config['xxx'], $config['xxxx'], $config['xxxxx']); if (mysqli_connect_errno()) {     printf("connect failed: %s\n", mysqli_connect_error());  exit; } $query = "select * files name in ('$names')"; $result = $sql->query($query);      if (!$result) {     var_dump($result);     //printf("query failed: %s\n", $mysqli->error);     //sendresponse(417, json_encode("query failed:"));     sendresponse(417, json_encode($decoded));  exit; }      $rows = array();     while($row = $result->fetch_row()) {         $rows[]=$row;     } sendresponse(200, json_encode($decoded));  $result->close(); $sql->close(); 

from above code query failed response, real strange thing null response sendresponse(417, json_encode($decoded)) or sendresponse(200, json_encode($decoded));

why null after query, after did not change $decode variable?

why query fails?

edit:::::

removing removing vardumbs correct json result , changing connection code solved problem know can correct query result.

$sql = new mysqli('localhost', 'user', 'password', 'database');     if (mysqli_connect_errno()) {         printf("connect failed: %s\n", mysqli_connect_error());      exit;     } 

i see mixing syntax of mysqli.

$sql = new mysqli($config['localhost'], $config['xxx'], $config['xxxx'],   $config['xxxxx']); if ($mysqli->connect_error) { 

you should use object oriented notation correspond using new. also, how writing config seems kind of strange, sure contents of config being obtained correctly?


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -