I'm trying to simply run a query and get the results in an array:
function run_query($query)
{
$out = '';
$db = new PDO("mysql:host=localhost;dbname=test","test","test");
$out = $db->query($query)->fetchAll(PDO::FETCH_OBJ);
return $out;
}
And on the other end:
$l_o_array = $php_functions->run_query('SHOW TABLES');
$temp = implode(',', $l_o_array);
Result: Catchable fatal error: Object of class stdClass could not be converted to string
I assume this is because I use FETCH_OBJ
, but what do I use to just get an array of strings?
Here's one way you might do it:
function run_query($query)
{
$out = '';
$db = new PDO("mysql:host=localhost;dbname=test","test","test");
$out = $db->query($query)->fetchAll();
return $out;
}
$results = run_query('SHOW TABLES');
$tables = array();
foreach($results as $result)
$tables[] = $result['Tables in test']; // Note, replace "test" with your database name
$temp = implode(',', $tables);
try print_R();
to under stand the proplem
<?php
$a = array ('a' => 'apple', 'b' => 'banana', 'c' => array ('x', 'y', 'z'));
print_r ($a);
?>
regard's
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.