Do I use PDO to query the database content like this? Why am I displaying this error?
(! ) Parse error: syntax error, unexpected 'foreach' (T_FOREACH) in D: \ wamp \ www \ cxblog. php on line 4
Is this an array? I just want to extract the values in the database. how should I write the values in the array form?
$ Pdo = new PDO ("mysql: host = localhost; dbname = t1", "root ","");
$ SQL = $ pdo-> query ('select * from blog ')
Foreach ($ SQL as $ row ){
Print_r ($ row );
}
?>
Reply to discussion (solution)
PDOStatement PDO: query (string statement)
Mixed PDOStatement: fetch ([int fetch_style [, int cursor_orientation [, int cursor_offset])
Array PDOStatement: fetchAll ([int fetch_style [, int column_index])
PDOStatement PDO: query (string statement)
Mixed PDOStatement: fetch ([int fetch_style [, int cursor_orientation [, int cursor_offset])
Array PDOStatement: fetchAll ([int fetch_style [, int column_index])
Cannot understand English
PDOStatement PDO: query (string statement)
Mixed PDOStatement: fetch ([int fetch_style [, int cursor_orientation [, int cursor_offset])
Array PDOStatement: fetchAll ([int fetch_style [, int column_index])
I know the problem. I have no ending semicolon before $ SQL. now an array is displayed, but I only want data.
This is the case.
query('select * from blog') $result = $sth->fetchall(PDO::FETCH_ASSOC); foreach($result as $k=>$v){ print_r($v);}?>
This is the case.
query('select * from blog') $result = $sth->fetchall(PDO::FETCH_ASSOC); foreach($result as $k=>$v){ print_r($v);}?>
I tried to remind me of this error. why?
(! ) Parse error: syntax error, unexpected '$ result' (T_VARIABLE) in D: \ wamp \ www \ cxblog2.php on line 4
This is the case.
query('select * from blog') $result = $sth->fetchall(PDO::FETCH_ASSOC); foreach($result as $k=>$v){ print_r($v);}?>
In this way, I only want to get the value in array format.
Of course, it is in the array format!
YOU select * from blog
This * indicates all the fields in the table. it is impossible for php to link them into a value beyond the limit.
Even if there is only one field in the table, php does not know it.
Because all the power of interpretation lies in you, not in php
Of course, it is in the array format!
YOU select * from blog
This * indicates all the fields in the table. it is impossible for php to link them into a value beyond the limit.
Even if there is only one field in the table, php does not know it.
Because all the power of interpretation lies in you, not in php
Only one column in my table is the content column. I can't change it to select content from blog.
As I have already said, php always returns an array for database queries.
$ Pdo = new PDO ("mysql: host = localhost; dbname = t1", "root ",""); $ Something = $ pdo-> query ('select * from blog') $ result = $ Something-> fetchall (PDO: FETCH_ASSOC ); foreach ($ result as $ k =>$ v) {echo $ v ['content']; // is this not the case but the value ?}
As I have already said, php always returns an array for database queries.
$ Pdo = new PDO ("mysql: host = localhost; dbname = t1", "root ",""); $ Something = $ pdo-> query ('select * from blog') $ result = $ Something-> fetchall (PDO: FETCH_ASSOC ); foreach ($ result as $ k =>$ v) {echo $ v ['content']; // is this not the case but the value ?}
Oh, yes. thank you for taking a look.