0

I am trying to get values of the enum into <option value="$enum">$enum</option> but so far without any luck.

I cannot really say why, the error I get is "Catchable fatal error: Object of class PDOStatement could not be converted to string in C:\xampp\htdocs\sp-admin\form.php on line 58"

line 58 is $result = str_replace(array("enum('", "')", "''"), array('', '', "'"), $result);

and here is my php

$query = "SELECT column_type FROM information_schema.columns
WHERE table_name = 'files' AND column_name = 'cat_page_pos'";
$result = $db->prepare($query);
    $result = str_replace(array("enum('", "')", "''"), array('', '', "'"), $result);
    $arr = explode("','", $result);
    return $arr;

please give me a hint here

thanks in advance

4
  • Please provide a print of $result. Commented Feb 3, 2014 at 16:37
  • I can't even try and begin to work out what you str_replace is trying to do. Could you explain what it is you are trying to replace and with what? The number of single and double quotes is making my brain die. Commented Feb 3, 2014 at 16:39
  • @TheHumbleRat here is my print PDOStatement Object ( [queryString] => SELECT column_type FROM information_schema.columns WHERE table_name = 'files' AND column_name = 'cat_page_pos' ) Commented Feb 3, 2014 at 16:42
  • 1
    Instead of using information_schema.columns, try using DESC table_name which is faster Commented Feb 3, 2014 at 16:44

1 Answer 1

1

Your $result object is not the result you expect but the PDO statement to fetch result from.

try something like this after your call to $db->prepare:

//perform SQL query on DB , since it has only be prepared
$result->execute();
//retrieve results from execution, here you obviously expect to get only one result
$data=$result->fetch();

$coltype=$data[0];

Then you'll find the string you want to process (with "enum('xxx','yyy')" in the $coltype variable)

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

2 Comments

Thanks for your hint, here is what I have now Array ( [column_type] => enum('0','1','2','3','4','5') [0] => enum('0','1','2','3','4','5') )
so now I will clean the returned result and use it in a way I needed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.