How to export partial rows of a MySQL table from WHERE clause?
P粉054616867
P粉054616867 2023-10-21 11:41:17
0
2
372

How to export certain rows of a MySQL table using where clause from a PHP script?

I have a MySQL say test and I want to use a PHP script to create an importable .sql file for rows with ids between 10 and 100.

I want to create a sql file test.sql, which can be imported into a MySQL database.

My code:

$con=mysqli_connect("localhost", "root","","mydatabase");

$tableName  = 'test';
$backupFile = '/opt/lampp/htdocs/practices/phpTest/test.sql';
$query      = "SELECT * INTO OUTFILE '$backupFile' FROM $tableName WHERE id BETWEEN 10 AND 500";

$result = mysqli_query($con,$query);

This creates a test.sql file but when I try to import it gives error #1064.

My script simply creates a file with rows containing column names and table structure or insert query.

P粉054616867
P粉054616867

reply all(2)
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!