2
require_once ('../configuration/data_conn.php');
ini_set('display_errors', 1);
error_reporting(E_ALL);

$sql = "
    SELECT  

    product.id,
    product.name,
    product.code,
    product.supplier,
    product.date_created,
    product.total

    FROM product";

$req_sql = $conn->prepare($sql);
$req_sql ->execute();
$data_sql = $req_sql ->fetchAll(PDO::FETCH_ASSOC);
print_r($data_sql);

I got only 3 fields :

[0] => Array
   (
    [id] => 1511
    [name] => mirror
    [code] => CD-13480

  )
[1] => Array
   (
    [id] => 1512
    [name] => chair
    [code] => CD-13481

  )

but when i use the same query in my database tool it works.

Im sure i have access to all these columns and i use in my php connection the same credentials to login to my database.

Thanks for any help.

23
  • Why are you preparing a query that has no parameters and you only want to run once? Commented Jan 3, 2017 at 16:42
  • Remove PDO::FETCH_ASSOC and test again. Commented Jan 3, 2017 at 16:43
  • Why would removing FETCH_ASSOC be the problem here @JustOnUnderMillions? Commented Jan 3, 2017 at 16:47
  • @RiggsFolly the OP may be on the way to creating a function which will run all of their queries. ¯\_(ツ)_/¯ Commented Jan 3, 2017 at 16:48
  • The same problem with FETCH_ASSOC. Commented Jan 3, 2017 at 16:49

1 Answer 1

1

I had a problem with the column supplier that contains special characters, I added type char for this field and it works now.

    $sql = "
          SELECT  
          product.id,
          product.name,
          product.code,
          product.supplier :: char(100),
          product.date_created,
          product.total

    FROM product";

Thanks for your help.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.