How to create table after create database using shell_script in PHP?

431 views Asked by At

After solve the issue to create a database using shell_script in php, see this post link, I was trying to create tables inside the same shell_exec command.

I have these lines:

$sql="CREATE DATABASE IF NOT EXISTS dbtest; use dbtest; CREATE TABLE MyGuests (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
firstname VARCHAR(30) NOT NULL,
lastname VARCHAR(30) NOT NULL,
email VARCHAR(50),
reg_date TIMESTAMP
) ";

shell_exec("mysql -uroot -pmypasswrd  -e  \"$sql\" ");

This code only creates the database, but not creates the table. My question is how accomplish this task using shell_exec()? Is it possible to run a sql satatment that comes from a mysqldump using shell_exec()?

1

There are 1 answers

1
RhinoLarva On BEST ANSWER

This code only creates the database, but not creates the table. My question is how accomplish this task using shell_exec()?

The only one solution I can find for your problem is to write your whole SQL query in one line (without breaking it into several lines). It will affect the readability of your code, but your table will be created.