Welcome Guest, Not a member yet? Register   Sign In
DB Create - Execute SQL Command
#1

[eluser]CI_avatar[/eluser]
I have SQL script imported from phpmyadmin. What I wanted is to
execute that script using CI(if there are functions available).

Database Forge Class is pretty promising but what I wanted is
to execute the script(as string) directly.

What are available functions in Database Forge are creating/deleting/editing database and tables. No function is available for executing script with "create database, create table and insert data" SQL command.

Please help.

Thank you in advance.
#2

[eluser]cideveloper[/eluser]
you dont need to use database forge if you just want to run sql

This worked for me

Code:
$query = $this->db->query("CREATE TABLE test (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,name VARCHAR(255));");
#3

[eluser]CI_avatar[/eluser]
@progr@mmer thank you. but the sql command that i am referring includes creating the database.
Like this

Code:
SET FOREIGN_KEY_CHECKS=0;

CREATE DATABASE `_rms_lotto_db`
    CHARACTER SET 'latin1'
    COLLATE 'latin1_swedish_ci';

USE `_rms_lotto_db`;

#
# Structure for the `_users` table :
#

CREATE TABLE `_users` (
  `username` varchar(20) NOT NULL,
  `password` varchar(160) DEFAULT NULL,
  `type` enum('ad','rp') DEFAULT 'rp',
  PRIMARY KEY (`username`),
  UNIQUE KEY `username` (`username`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;




Theme © iAndrew 2016 - Forum software by © MyBB