CodeIgniter Forums
DB Create - Execute SQL Command - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: DB Create - Execute SQL Command (/showthread.php?tid=37575)



DB Create - Execute SQL Command - El Forum - 01-13-2011

[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.


DB Create - Execute SQL Command - El Forum - 01-13-2011

[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));");



DB Create - Execute SQL Command - El Forum - 01-13-2011

[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;