MySQL table names read from the backup

Hello,

How do I read MySQL table names and number of INSERT from the backup?

Example:

With this I read the table name, How do I read INSERT line number?


[php]
$search = ‘foo’;
$lines = file(‘file.txt’);
// Store true when the text is found
$found = false;
foreach($lines as $line)
{
if(strpos($line, $search) !== false)
{
$found = true;
echo $line;
}
}
// If the text was not found, show a message
if(!$found)
{
echo ‘No match found’;
}
[/php]

Thank you in advance

Table name Ok,
How do I get the number of rows insert?
Number of insert rows of each table ?
[php]

<?php @$lines = file('backup.sql'); @$search = 'CREATE TABLE'; @$search2 = 'INSERT'; $found = false; $i = 1; foreach($lines as $line) { if(strpos($line, $search) !== false) {

$found = true;
$explode = explode(" ",$line);
$result = trim($explode[2]);
?>





<?php $i++; unset($result, $line, $explode); } } ?>
Order Table Name Rows
<?=$i?> <?=ucfirst(str_replace("`","",$result))?> Number of insert rows of each table ?
[/php]

Hello again,
Can you help please?

My database backup example
[php]$lines = file(‘backup.sql’);[/php]
[php]


CREATE TABLE table_name (
/* table structure */
}

INSERT INTO table_name VALUES(’’,’’,’’);
INSERT INTO table_name VALUES(’’,’’,’’);
INSERT INTO table_name VALUES(’’,’’,’’);


CREATE TABLE table_nam2 (
/* table structure */
}

INSERT INTO table_name2 VALUES(’’,’’,’’);
INSERT INTO table_name2 VALUES(’’,’’,’’);


CREATE TABLE table_name3 (
/* table structure */
}


[/php]

Sample output:
[php]
ORDER TABLE NAME ROWS

1 table_name 3
2 table_name2 2
3 table_name3 0
[/php]

Table name list, OK
Problem, Number of insert rows of each table ?, How do I get?

How to add the following code to do?
[php]

<?php $lines = file('backup.sql');

$search = 'CREATE TABLE '; // CREATE TABLE table_name (
$insert_search = 'INSERT INTO '; // INSERT INTO table_name VALUES(‘24’,‘2’,‘14’);
$found = false;
$i = 1;
foreach($lines as $line){

if(strpos($line, $search) !== false){
$found = true;
$rawdata = explode("\n", $line);
$data = explode("`", $rawdata[0]);
array_pop($data);
$tablename = array_pop($data);

?>





<?php $i++; unset($tablename, $line, $data, $rawdata); } // if(strpos($line, $search) !== false){ } // foreach($lines as $line){ ?>
Order Table Name Rows
<?=$i?> <?=ucfirst(strtolower($tablename))?> HERE, Number of insert rows of each table ?
[/php]

Best Regards

Sponsor our Newsletter | Privacy Policy | Terms of Service