No database selected in codeigniter Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) Data science time! April 2019 and salary with experience Should we burninate the [wrap] tag? The Ask Question Wizard is Live!How should I choose an authentication library for CodeIgniter?Fatal Error: Allowed Memory Size of 134217728 Bytes Exhausted (CodeIgniter + XML-RPC)Trouble changing databases for my models in codeigniterCodeIgniter Upload and Resize ProblemCannot connect to SQL Server 2012 from codeigniter 2.1.4upgrading from php 5.3 to php 5.5 showing connection errorMultiple database- access data from the 3rd database using codeigniterStoring Variables in Database classDebugging “Unable to connect to your database server using the provided settings” in CodeIgniterCodeigniter Can't Connect to External SQL Server

Single word antonym of "flightless"

Seeking colloquialism for “just because”

What causes the vertical darker bands in my photo?

What is the logic behind the Maharil's explanation of why we don't say שעשה ניסים on Pesach?

Should I use a zero-interest credit card for a large one-time purchase?

What is Wonderstone and are there any references to it pre-1982?

What does this icon in iOS Stardew Valley mean?

Extract all GPU name, model and GPU ram

The logistics of corpse disposal

How to react to hostile behavior from a senior developer?

How to answer "Have you ever been terminated?"

Storing hydrofluoric acid before the invention of plastics

Short Story with Cinderella as a Voo-doo Witch

At the end of Thor: Ragnarok why don't the Asgardians turn and head for the Bifrost as per their original plan?

What is a non-alternating simple group with big order, but relatively few conjugacy classes?

Withdrew £2800, but only £2000 shows as withdrawn on online banking; what are my obligations?

3 doors, three guards, one stone

Resolving to minmaj7

How to find out what spells would be useless to a blind NPC spellcaster?

Using audio cues to encourage good posture

If a contract sometimes uses the wrong name, is it still valid?

Do I really need recursive chmod to restrict access to a folder?

Is it ethical to give a final exam after the professor has quit before teaching the remaining chapters of the course?

Is it true that "carbohydrates are of no use for the basal metabolic need"?



No database selected in codeigniter



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
Data science time! April 2019 and salary with experience
Should we burninate the [wrap] tag?
The Ask Question Wizard is Live!How should I choose an authentication library for CodeIgniter?Fatal Error: Allowed Memory Size of 134217728 Bytes Exhausted (CodeIgniter + XML-RPC)Trouble changing databases for my models in codeigniterCodeIgniter Upload and Resize ProblemCannot connect to SQL Server 2012 from codeigniter 2.1.4upgrading from php 5.3 to php 5.5 showing connection errorMultiple database- access data from the 3rd database using codeigniterStoring Variables in Database classDebugging “Unable to connect to your database server using the provided settings” in CodeIgniterCodeigniter Can't Connect to External SQL Server



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I have made this function to take values from the form and overwrite the config/database.php.



 function configure_database() 
// write database.php
$data_db = file_get_contents('./uploads/database.php');
// session_start();
$data_db = str_replace('%DATABASE%', $_SESSION['dbname'], $data_db);
$data_db = str_replace('%USERNAME%', $_SESSION['username'], $data_db);
$data_db = str_replace('%PASSWORD%', $_SESSION['password'], $data_db);
$data_db = str_replace('%HOSTNAME%', $_SESSION['hostname'], $data_db);
file_put_contents('./application/config/database.php', $data_db);
$this->run_blank_sql();



and it successfully overwrites the config/database.php. at the last of the function I have written the $this->run_blank_sql(); which calls the run_blank_sql() I have written this function to run the SQL in uploads directory.



function run_blank_sql() 
$this->load->database();
// Set line to collect lines that wrap
$templine = '';
// Read in entire file
$lines = file('./uploads/install.sql');
// Loop through each line
foreach ($lines as $line)
// Skip it if it's a comment
if (substr($line, 0, 2) == '--'



But it gives me that error.



enter image description here



the configure_database() overwrites these values successfully.



'hostname' => '%HOSTNAME%',
'username' => '%USERNAME%',
'password' => '%PASSWORD%',
'database' => '%DATABASE%',
'dbdriver' => 'mysqli',


To



'hostname' => 'localhost',
'username' => 'root',
'password' => *****,
'database' => 'studentPortal',
'dbdriver' => 'mysqli',









share|improve this question
























  • you have plenty of code here but I don't see the rows that are causing the error. Post the relevant code please

    – Lelio Faieta
    Mar 22 at 9:14











  • Ok. Simply look at this function run_blank_sql(). in this $this->load->database(); not working here. I want to Install SQL which will create the table in DB but it says no DB selected.

    – Waqas Ahmad
    Mar 22 at 9:16












  • You need to read codeigniter.com/user_guide/database/… - you can pass an array of config options and then load the database. I think you're trying to amend the config file which is not the correct way of doing it.

    – Antony
    Mar 22 at 9:19











  • $data_db = str_replace('%DATABASE%', $_SESSION['dbname'], $data_db); Add a log and see $data_db the variable that you've overwritten.

    – Harshana
    Mar 22 at 9:19












  • @Harshana it successfully overwrites the DB name in the config/database.php.

    – Waqas Ahmad
    Mar 22 at 9:38

















0















I have made this function to take values from the form and overwrite the config/database.php.



 function configure_database() 
// write database.php
$data_db = file_get_contents('./uploads/database.php');
// session_start();
$data_db = str_replace('%DATABASE%', $_SESSION['dbname'], $data_db);
$data_db = str_replace('%USERNAME%', $_SESSION['username'], $data_db);
$data_db = str_replace('%PASSWORD%', $_SESSION['password'], $data_db);
$data_db = str_replace('%HOSTNAME%', $_SESSION['hostname'], $data_db);
file_put_contents('./application/config/database.php', $data_db);
$this->run_blank_sql();



and it successfully overwrites the config/database.php. at the last of the function I have written the $this->run_blank_sql(); which calls the run_blank_sql() I have written this function to run the SQL in uploads directory.



function run_blank_sql() 
$this->load->database();
// Set line to collect lines that wrap
$templine = '';
// Read in entire file
$lines = file('./uploads/install.sql');
// Loop through each line
foreach ($lines as $line)
// Skip it if it's a comment
if (substr($line, 0, 2) == '--'



But it gives me that error.



enter image description here



the configure_database() overwrites these values successfully.



'hostname' => '%HOSTNAME%',
'username' => '%USERNAME%',
'password' => '%PASSWORD%',
'database' => '%DATABASE%',
'dbdriver' => 'mysqli',


To



'hostname' => 'localhost',
'username' => 'root',
'password' => *****,
'database' => 'studentPortal',
'dbdriver' => 'mysqli',









share|improve this question
























  • you have plenty of code here but I don't see the rows that are causing the error. Post the relevant code please

    – Lelio Faieta
    Mar 22 at 9:14











  • Ok. Simply look at this function run_blank_sql(). in this $this->load->database(); not working here. I want to Install SQL which will create the table in DB but it says no DB selected.

    – Waqas Ahmad
    Mar 22 at 9:16












  • You need to read codeigniter.com/user_guide/database/… - you can pass an array of config options and then load the database. I think you're trying to amend the config file which is not the correct way of doing it.

    – Antony
    Mar 22 at 9:19











  • $data_db = str_replace('%DATABASE%', $_SESSION['dbname'], $data_db); Add a log and see $data_db the variable that you've overwritten.

    – Harshana
    Mar 22 at 9:19












  • @Harshana it successfully overwrites the DB name in the config/database.php.

    – Waqas Ahmad
    Mar 22 at 9:38













0












0








0








I have made this function to take values from the form and overwrite the config/database.php.



 function configure_database() 
// write database.php
$data_db = file_get_contents('./uploads/database.php');
// session_start();
$data_db = str_replace('%DATABASE%', $_SESSION['dbname'], $data_db);
$data_db = str_replace('%USERNAME%', $_SESSION['username'], $data_db);
$data_db = str_replace('%PASSWORD%', $_SESSION['password'], $data_db);
$data_db = str_replace('%HOSTNAME%', $_SESSION['hostname'], $data_db);
file_put_contents('./application/config/database.php', $data_db);
$this->run_blank_sql();



and it successfully overwrites the config/database.php. at the last of the function I have written the $this->run_blank_sql(); which calls the run_blank_sql() I have written this function to run the SQL in uploads directory.



function run_blank_sql() 
$this->load->database();
// Set line to collect lines that wrap
$templine = '';
// Read in entire file
$lines = file('./uploads/install.sql');
// Loop through each line
foreach ($lines as $line)
// Skip it if it's a comment
if (substr($line, 0, 2) == '--'



But it gives me that error.



enter image description here



the configure_database() overwrites these values successfully.



'hostname' => '%HOSTNAME%',
'username' => '%USERNAME%',
'password' => '%PASSWORD%',
'database' => '%DATABASE%',
'dbdriver' => 'mysqli',


To



'hostname' => 'localhost',
'username' => 'root',
'password' => *****,
'database' => 'studentPortal',
'dbdriver' => 'mysqli',









share|improve this question
















I have made this function to take values from the form and overwrite the config/database.php.



 function configure_database() 
// write database.php
$data_db = file_get_contents('./uploads/database.php');
// session_start();
$data_db = str_replace('%DATABASE%', $_SESSION['dbname'], $data_db);
$data_db = str_replace('%USERNAME%', $_SESSION['username'], $data_db);
$data_db = str_replace('%PASSWORD%', $_SESSION['password'], $data_db);
$data_db = str_replace('%HOSTNAME%', $_SESSION['hostname'], $data_db);
file_put_contents('./application/config/database.php', $data_db);
$this->run_blank_sql();



and it successfully overwrites the config/database.php. at the last of the function I have written the $this->run_blank_sql(); which calls the run_blank_sql() I have written this function to run the SQL in uploads directory.



function run_blank_sql() 
$this->load->database();
// Set line to collect lines that wrap
$templine = '';
// Read in entire file
$lines = file('./uploads/install.sql');
// Loop through each line
foreach ($lines as $line)
// Skip it if it's a comment
if (substr($line, 0, 2) == '--'



But it gives me that error.



enter image description here



the configure_database() overwrites these values successfully.



'hostname' => '%HOSTNAME%',
'username' => '%USERNAME%',
'password' => '%PASSWORD%',
'database' => '%DATABASE%',
'dbdriver' => 'mysqli',


To



'hostname' => 'localhost',
'username' => 'root',
'password' => *****,
'database' => 'studentPortal',
'dbdriver' => 'mysqli',






php codeigniter






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 22 at 9:12









Daniel E.

2,19011024




2,19011024










asked Mar 22 at 9:07









Waqas AhmadWaqas Ahmad

19913




19913












  • you have plenty of code here but I don't see the rows that are causing the error. Post the relevant code please

    – Lelio Faieta
    Mar 22 at 9:14











  • Ok. Simply look at this function run_blank_sql(). in this $this->load->database(); not working here. I want to Install SQL which will create the table in DB but it says no DB selected.

    – Waqas Ahmad
    Mar 22 at 9:16












  • You need to read codeigniter.com/user_guide/database/… - you can pass an array of config options and then load the database. I think you're trying to amend the config file which is not the correct way of doing it.

    – Antony
    Mar 22 at 9:19











  • $data_db = str_replace('%DATABASE%', $_SESSION['dbname'], $data_db); Add a log and see $data_db the variable that you've overwritten.

    – Harshana
    Mar 22 at 9:19












  • @Harshana it successfully overwrites the DB name in the config/database.php.

    – Waqas Ahmad
    Mar 22 at 9:38

















  • you have plenty of code here but I don't see the rows that are causing the error. Post the relevant code please

    – Lelio Faieta
    Mar 22 at 9:14











  • Ok. Simply look at this function run_blank_sql(). in this $this->load->database(); not working here. I want to Install SQL which will create the table in DB but it says no DB selected.

    – Waqas Ahmad
    Mar 22 at 9:16












  • You need to read codeigniter.com/user_guide/database/… - you can pass an array of config options and then load the database. I think you're trying to amend the config file which is not the correct way of doing it.

    – Antony
    Mar 22 at 9:19











  • $data_db = str_replace('%DATABASE%', $_SESSION['dbname'], $data_db); Add a log and see $data_db the variable that you've overwritten.

    – Harshana
    Mar 22 at 9:19












  • @Harshana it successfully overwrites the DB name in the config/database.php.

    – Waqas Ahmad
    Mar 22 at 9:38
















you have plenty of code here but I don't see the rows that are causing the error. Post the relevant code please

– Lelio Faieta
Mar 22 at 9:14





you have plenty of code here but I don't see the rows that are causing the error. Post the relevant code please

– Lelio Faieta
Mar 22 at 9:14













Ok. Simply look at this function run_blank_sql(). in this $this->load->database(); not working here. I want to Install SQL which will create the table in DB but it says no DB selected.

– Waqas Ahmad
Mar 22 at 9:16






Ok. Simply look at this function run_blank_sql(). in this $this->load->database(); not working here. I want to Install SQL which will create the table in DB but it says no DB selected.

– Waqas Ahmad
Mar 22 at 9:16














You need to read codeigniter.com/user_guide/database/… - you can pass an array of config options and then load the database. I think you're trying to amend the config file which is not the correct way of doing it.

– Antony
Mar 22 at 9:19





You need to read codeigniter.com/user_guide/database/… - you can pass an array of config options and then load the database. I think you're trying to amend the config file which is not the correct way of doing it.

– Antony
Mar 22 at 9:19













$data_db = str_replace('%DATABASE%', $_SESSION['dbname'], $data_db); Add a log and see $data_db the variable that you've overwritten.

– Harshana
Mar 22 at 9:19






$data_db = str_replace('%DATABASE%', $_SESSION['dbname'], $data_db); Add a log and see $data_db the variable that you've overwritten.

– Harshana
Mar 22 at 9:19














@Harshana it successfully overwrites the DB name in the config/database.php.

– Waqas Ahmad
Mar 22 at 9:38





@Harshana it successfully overwrites the DB name in the config/database.php.

– Waqas Ahmad
Mar 22 at 9:38












2 Answers
2






active

oldest

votes


















0














It says clearly in
enter image description here
that No Database Selected




I think, You need to specify



$db['default']['database'] = "YOUR_DB"; 


in /application/config/database.php






share|improve this answer























  • DB is successfully connected. but this statement not working $this->load->database();

    – Waqas Ahmad
    Mar 22 at 14:43











  • what is the error now? @JohnDoe

    – Josua Marcel Chrisano
    Mar 23 at 8:07












  • In application/config/autoload.php add this : $autoload['libraries'] = array('database'); // add database in array

    – Josua Marcel Chrisano
    Mar 23 at 8:18


















0














Wherever you are running the drop (I don't see that in your code) is the problem. You're dropping a table but are not specifying the schema where that table is.



Even if you have only one table called category you need to be specific about what schema it lives in. Change your drop statement to be: drop table schema.category.



This hasn't got anything to do with the $db['default']['database'] = "YOUR_DB"; in the configuration. It's just standard SQL






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55296163%2fno-database-selected-in-codeigniter%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    It says clearly in
    enter image description here
    that No Database Selected




    I think, You need to specify



    $db['default']['database'] = "YOUR_DB"; 


    in /application/config/database.php






    share|improve this answer























    • DB is successfully connected. but this statement not working $this->load->database();

      – Waqas Ahmad
      Mar 22 at 14:43











    • what is the error now? @JohnDoe

      – Josua Marcel Chrisano
      Mar 23 at 8:07












    • In application/config/autoload.php add this : $autoload['libraries'] = array('database'); // add database in array

      – Josua Marcel Chrisano
      Mar 23 at 8:18















    0














    It says clearly in
    enter image description here
    that No Database Selected




    I think, You need to specify



    $db['default']['database'] = "YOUR_DB"; 


    in /application/config/database.php






    share|improve this answer























    • DB is successfully connected. but this statement not working $this->load->database();

      – Waqas Ahmad
      Mar 22 at 14:43











    • what is the error now? @JohnDoe

      – Josua Marcel Chrisano
      Mar 23 at 8:07












    • In application/config/autoload.php add this : $autoload['libraries'] = array('database'); // add database in array

      – Josua Marcel Chrisano
      Mar 23 at 8:18













    0












    0








    0







    It says clearly in
    enter image description here
    that No Database Selected




    I think, You need to specify



    $db['default']['database'] = "YOUR_DB"; 


    in /application/config/database.php






    share|improve this answer













    It says clearly in
    enter image description here
    that No Database Selected




    I think, You need to specify



    $db['default']['database'] = "YOUR_DB"; 


    in /application/config/database.php







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Mar 22 at 10:41









    Josua Marcel ChrisanoJosua Marcel Chrisano

    3,62243780




    3,62243780












    • DB is successfully connected. but this statement not working $this->load->database();

      – Waqas Ahmad
      Mar 22 at 14:43











    • what is the error now? @JohnDoe

      – Josua Marcel Chrisano
      Mar 23 at 8:07












    • In application/config/autoload.php add this : $autoload['libraries'] = array('database'); // add database in array

      – Josua Marcel Chrisano
      Mar 23 at 8:18

















    • DB is successfully connected. but this statement not working $this->load->database();

      – Waqas Ahmad
      Mar 22 at 14:43











    • what is the error now? @JohnDoe

      – Josua Marcel Chrisano
      Mar 23 at 8:07












    • In application/config/autoload.php add this : $autoload['libraries'] = array('database'); // add database in array

      – Josua Marcel Chrisano
      Mar 23 at 8:18
















    DB is successfully connected. but this statement not working $this->load->database();

    – Waqas Ahmad
    Mar 22 at 14:43





    DB is successfully connected. but this statement not working $this->load->database();

    – Waqas Ahmad
    Mar 22 at 14:43













    what is the error now? @JohnDoe

    – Josua Marcel Chrisano
    Mar 23 at 8:07






    what is the error now? @JohnDoe

    – Josua Marcel Chrisano
    Mar 23 at 8:07














    In application/config/autoload.php add this : $autoload['libraries'] = array('database'); // add database in array

    – Josua Marcel Chrisano
    Mar 23 at 8:18





    In application/config/autoload.php add this : $autoload['libraries'] = array('database'); // add database in array

    – Josua Marcel Chrisano
    Mar 23 at 8:18













    0














    Wherever you are running the drop (I don't see that in your code) is the problem. You're dropping a table but are not specifying the schema where that table is.



    Even if you have only one table called category you need to be specific about what schema it lives in. Change your drop statement to be: drop table schema.category.



    This hasn't got anything to do with the $db['default']['database'] = "YOUR_DB"; in the configuration. It's just standard SQL






    share|improve this answer



























      0














      Wherever you are running the drop (I don't see that in your code) is the problem. You're dropping a table but are not specifying the schema where that table is.



      Even if you have only one table called category you need to be specific about what schema it lives in. Change your drop statement to be: drop table schema.category.



      This hasn't got anything to do with the $db['default']['database'] = "YOUR_DB"; in the configuration. It's just standard SQL






      share|improve this answer

























        0












        0








        0







        Wherever you are running the drop (I don't see that in your code) is the problem. You're dropping a table but are not specifying the schema where that table is.



        Even if you have only one table called category you need to be specific about what schema it lives in. Change your drop statement to be: drop table schema.category.



        This hasn't got anything to do with the $db['default']['database'] = "YOUR_DB"; in the configuration. It's just standard SQL






        share|improve this answer













        Wherever you are running the drop (I don't see that in your code) is the problem. You're dropping a table but are not specifying the schema where that table is.



        Even if you have only one table called category you need to be specific about what schema it lives in. Change your drop statement to be: drop table schema.category.



        This hasn't got anything to do with the $db['default']['database'] = "YOUR_DB"; in the configuration. It's just standard SQL







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 22 at 13:14









        Javier LarrouletJavier Larroulet

        1,5391521




        1,5391521



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55296163%2fno-database-selected-in-codeigniter%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현