CodeIgniter Forums
Importing .sql files - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Importing .sql files (/showthread.php?tid=89316)



Importing .sql files - jetspeed - 02-05-2024

Hi guys,
I have a sql file exported from phpMyAdmin. Is there a way to import this file via the CI database classes? I tried reading the contents and then running it via simpleQuery() but it threw an exception.


RE: Importing .sql files - kenjis - 02-05-2024

See https://forum.codeigniter.com/showthread.php?tid=63410

The code is for CI3, but it can be ported to CI4 easily.


RE: Importing .sql files - jetspeed - 02-05-2024

Thanks, it looks rather messy, so I found a library that can restore a sql file. If someone else reads this in the future, try https://github.com/ifsnop/mysqldump-php


RE: Importing .sql files - kenjis - 02-05-2024

It seems the package does not provide feature to import.
But there is a sample code to import:
https://github.com/ifsnop/mysqldump-php/wiki/Importing-dump-from-php


RE: Importing .sql files - jetspeed - 02-05-2024

(02-05-2024, 05:06 PM)kenjis Wrote: It seems the package does not provide feature to import.
But there is a sample code to import:
https://github.com/ifsnop/mysqldump-php/wiki/Importing-dump-from-php

There's no documented example but there is a "restore" function in the class which looks to use to incorporate that same code. The readme says one of the features is:
Code:
can restore a dump from a file, when no mysql executable is available.

I was able to use it to restore a dump.