1
I’m having problems while creating the database automatically via PHP. I am developing a college MVC project and wanted to import the sql file and through a query create the tables.
In the previous part of the code is made the connection with the database and also the creation of the database also via query and both work perfectly; but when creating the tables nothing happens or errors, the code is as follows:
$sql = file_get_contents(BASE_URL."database/arquivo.sql");
echo $sql;
$this->connection->multi_query($sql);
I’ve tried with query()
and multi_query()
and nothing happens, which could be wrong?
Guys, the sql file link is this: https://www.dropbox.com/s/edp8uhifnl2mw97/lapesa.sql?dl=0
is indicating the following error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_' at line 12
If I delete this line, the error continues for the following lines, I am unable to resolve.
Could you put part of the.sql file content? see if this returns any errors:
$res = $this->connection->multi_query($sql);
if(!$res){
 echo $this->error;
}
.– rray
The content of the sql file is generated by phpmyadmin, so there are no syntax errors or anything like that, I just need to generate it automatically because I will have to export the project
– leandroungari
I had forgotten to comment on that in the question
– leandroungari
The screen is blank? checked if the error display is not hidden.
– rray
Error display is enabled and screen has not turned white, is showing all mounted view
– leandroungari
It could be your connection...
– Jorge B.
I tested here part of sql file and had the same error, so I removed the header(comments) and table
administrador
I changed the primary key ofid
forid_admin
– rray
ai worked perfectly?
– leandroungari
perfect, worked just right
– leandroungari