0

I want to delete specific row from multiple mysql tables at a time. The tables have a common column.

I save the table names in an array like this :

$tables = array('table1','table2','table3','table4');
foreach($tables as $table) {
$query = $con->query("DELETE FROM $table WHERE Column='somevalue'");
}

if($query === FALSE) {
echo "Error : " . $query . $con->error;
}

Is this a way to delete rows from multiple tables at once? Please excuse me if this is a silly question. I am not an expert in PHP and MySql..

2

1 Answer 1

1

To delete tables you have to use the drop command. Just use DROP with the mysql tables that you want to drop separated by commas:

ex: DROP TABLE T1, T2, T3

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

2 Comments

I have to delete specific rows from multiple tables, not entire tables.
Ah okay. Then the way you have should work. However, it would be vulnerable to a MySQL injection attack if any part of the sql string is coming from the user. If this is the case, look into escaping the data you are getting from the user.

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.