Welcome Guest, Not a member yet? Register   Sign In
Load database script and execute
#1

[eluser]Ricardo SDL[/eluser]
Hi fellows! I have a database script that generates my tables and other things in the database. It looks like:
Code:
drop table if exists users;
CREATE TABLE `users` (
`id` INT NOT NULL AUTO_INCREMENT ,
`register_date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ,
`user_name` VARCHAR(20) NOT NULL ,
`email` VARCHAR(100) ,
`password` VARCHAR(100) NOT NULL ,
PRIMARY KEY (`id`) ,
UNIQUE (
`user_name`
)
) ENGINE = InnoDB;

CREATE TABLE `categories` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`name` VARCHAR( 20 ) NOT NULL ,
`description` VARCHAR( 256 ) NULL ,
`language` VARCHAR( 5 ) NULL ,
`create_date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE = InnoDB ;
I tried to load this script from a text file and execute it through $this->db->query() function.
I've got some errors, the script is fine (the part above is for illustration only). Can the codeigniter execute queries like this one or I must change the script?
I'm using mysql 5.0.67 and codeigniter 1.7.1.
Thanks in advance.
#2

[eluser]Thorpe Obazee[/eluser]
CI can run the 3 queries. They are still SQL queries.

You'll probably need to separate the queries into different $this->db->query() calls.
#3

[eluser]Ricardo SDL[/eluser]
The errors that I'm getting are as if the sql code was wrong. I'm trying to run the whole file at once sending it like a string to the "$this->db->query()" function.
I'll try what you said bargainph.




Theme © iAndrew 2016 - Forum software by © MyBB