0

im using this php code to concat two querys:

$qry = "Create Table $this->tablename (".
                "id_user BIGINT NOT NULL AUTO_INCREMENT ,".
                "name VARCHAR( 128 ) NOT NULL ,".
                "lastname VARCHAR( 128 ) NOT NULL ,".
                "email VARCHAR( 128 ) NOT NULL ,".
                "password VARCHAR( 32 ) NOT NULL ,".
                "confirmcode VARCHAR(32) ,".
                "ident_number VARCHAR( 128 ) NOT NULL ,".
                "professional_area VARCHAR( 128 ) NOT NULL ,".
                "last_update_cv DATETIME NOT NULL ,".
                "last_login DATETIME NOT NULL ,".
                "PRIMARY KEY ( id_user )".
                ");";
$qry = $qry . "CREATE TABLE ". table_cv . 
" (id_cv BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY , 
id_user BIGINT NOT NULL, 
phone_number VARCHAR(35) NOT NULL, 
profile_text VARCHAR(500) NOT NULL);";

Any time i send the query i get a syntax error.
What is the correct way to do two queries in single execution?

3 Answers 3

1

If you are using PHP 5 you can use multi_query

http://www.php.net/manual/en/mysqli.multi-query.php

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

Comments

0

Use a HEREDOC:

$sql = <<<EOL
Create Table {$this->tablename} (
    id_user BIGINT NOT NULL AUTO_INCREMENT,
    name VARCHAR( 128 ) NOT NULL ,
    lastname VARCHAR( 128 ) NOT NULL ,
    email VARCHAR( 128 ) NOT NULL ,
    password VARCHAR( 32 ) NOT NULL ,
    confirmcode VARCHAR(32) ,
    ident_number VARCHAR( 128 ) NOT NULL ,
    professional_area VARCHAR( 128 ) NOT NULL ,
    last_update_cv DATETIME NOT NULL ,
    last_login DATETIME NOT NULL ,
    PRIMARY KEY ( id_user )
);
EOL;

They make it very easy to generate multi-line strings. However, note that MySQL's PHP driver does NOT allow multiple queries to be issued in a single query call as a security restriction (it eliminates a large class of SQL injection attacks).

You'll have to issue two separate queries.

Comments

0

are you using multi_query? http://php.net/manual/en/mysqli.multi-query.php

Comments

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.