I can’t seem to find this information in other questions, even though I think it is a basic problem.
In mySQL, I’m attempting to COUNT the number of rows in column “rowid” from the one table that occurs in thousands of different schemas (therefore listing the schemas individually is impractical).
Note: some schemas do not have the table, and therefore no information.
Thanks!
Edit:
I attempted the script below and it kept returning:
Fatal error: Call to a member function execute() …
This was on the SECOND execute function. To fix this, I manually input the result of the first sql into the second variable sql but that gave me:
Fatal error: Call to a member function prepare() on a non-object in _____ on line 18 (aka the first prepare statement)
Here is the code. You’ll see I’ve been playing around with it a bunch (I used a different connect method to see if that changed anything)
<html>
<head>
</head>
<body>
<?php
$db = mysql_connect(localhost,******, *******);
$sql = "SELECT TABLE_SCHEMA, TABLE_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'Ftrans /*this is our specific table name*/'
AND COLUMN_NAME = 'rowid'";
$stmt = $db->prepare($sql); /*this is where I got the second error*/
$stmt->execute();
while ($row = $stmt->fetchObject()) {
// $sql2 = "SELECT COUNT(*) FROM $row->TABLE_SCHEMA.$row->TABLE_NAME";
$sql2 = "SELECT COUNT(*) FROM fp_AIRG.Ftransi";
$stmt2 = $db->prepare($sql2);
$stmt2->execute();
$count = $stmt2->fetchColumn();
}
mysql_close($db);
?>
</body>
</html>
Then for each record returned –
Here is a PHP based implementation –
I have not run this so it may have some errors in it but it should get you heading in the right direction.