Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] Unable to connect to the database
#1

(This post was last modified: 05-18-2021, 12:07 AM by John_Betong.)

Good morning i have a Project in a subfolder , the system work fine but i cannnot connect to db , file env its ok and if i try to connect with adminer ( similar to Phpmyadmin ) and same credential of file env It connect. Wath can i do?
Reply
#2

You need to show us your config database file setup to be able to help you.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

(This post was last modified: 05-16-2021, 06:26 AM by pippuccio76.)

(05-16-2021, 04:15 AM)InsiteFX Wrote: You need to show us your config database file setup to be able to help you.
see my env with xxx in credential . edited name from .env to env.txt to upload

Attached Files
.txt   env.txt (Size: 4.09 KB / Downloads: 11)
Reply
#4

(This post was last modified: 05-16-2021, 03:34 PM by InsiteFX. Edit Reason: Spelliing error )

Did you try the config database settings alone to see if they work?
Also the base_url in your env.txt should have an ending backslash on it \

You can try this to see if you can connect stand alone.

PHP Code:
<?php
// Code to create the database

// Add your own username and password
$serverName "localhost";
$userName   "username";
$password   "password";

// Create the Database Connection
$connId mysqli_connect($serverName$userName$password);

// Check the Database Connection
if ($connId === false)
{
    exit("ERROR: Could not connect. " mysqli_connect_error());


// Create the Database
// Add your datya
$sql "CREATE DATABASE yourDatabaseName";

// Check that the Database was created
if (mysqli_query($connId$sql))
{
    echo "Database created successfully";
}
else
{
    echo "ERROR: Creating Database. " mysqli_error($connId);
}

// Close the Connection
mysqli_close($connId);

?>
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#5

(05-16-2021, 03:32 PM)InsiteFX Wrote: Did you try the config database settings alone to see if they work?
Also the base_url in your env.txt should have an ending backslash on it \

You can try this to see if you can connect stand alone.

PHP Code:
<?php
// Code to create the database

// Add your own username and password
$serverName "localhost";
$userName   "username";
$password   "password";

// Create the Database Connection
$connId mysqli_connect($serverName$userName$password);

// Check the Database Connection
if ($connId === false)
{
    exit("ERROR: Could not connect. " mysqli_connect_error());


// Create the Database
// Add your datya
$sql "CREATE DATABASE yourDatabaseName";

// Check that the Database was created
if (mysqli_query($connId$sql))
{
    echo "Database created successfully";
}
else
{
    echo "ERROR: Creating Database. " mysqli_error($connId);
}

// Close the Connection
mysqli_close($connId);

?>
i Change your code :


PHP Code:
<?php
// Code to create the database

// Add your own username and password
$serverName "localhost";
$userName   "xxxx";
$password   "xxxx";

// Create the Database Connection
$connId mysqli_connect($serverName$userName$password);

// Check the Database Connection
if ($connId === false)
{
    exit("ERROR: Could not connect. " mysqli_connect_error());


// Create the Database
// Add your datya
$sql "select * from xxxx.admin";

// Check that the Database was created
if (mysqli_query($connId$sql))
{
    echo "Database created successfully";
}
else
{
    echo "ERROR: Creating Database. " mysqli_error($connId);
}

// Close the Connection
mysqli_close($connId);

?>
and result is : Database created successfully 
Reply
#6

In your database settings in the .env change localhost to 27.0.0.1 and see if that works.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#7

(05-16-2021, 08:31 PM)InsiteFX Wrote: In your database settings in the .env change localhost to 27.0.0.1 and see if that works.
Same problem connection Is AN empty array
Reply
#8

(This post was last modified: 05-17-2021, 01:26 AM by InsiteFX.)

Did you do away with the .env file and try using the Config\Database.php settings?

This makes no sense, I use databases all the time and never have a problem.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#9

(This post was last modified: 05-17-2021, 04:05 AM by pippuccio76.)

(05-17-2021, 01:24 AM)InsiteFX Wrote: Did you do away with the .env file and try using the Config\Database.php settings?

This makes no sense, I use databases all the time and never have a problem.
i try both  config/database and env same problem

(05-17-2021, 03:11 AM)pippuccio76 Wrote:
(05-17-2021, 01:24 AM)InsiteFX Wrote: Did you do away with the .env file and try using the Config\Database.php settings?

This makes no sense, I use databases all the time and never have a problem.
i try both  config/database and env same problem
i try to use the script at this tread :

https://forum.codeigniter.com/thread-77479.html

this is the error:

mysqli::__construct(): Headers and client library minor version mismatch. Headers:50650 Library:50528

[url=https://www.google.com/search?q=ErrorException+mysqli%3A%3A__construct%28%29%3A+Headers+and+client+library+minor+version+mismatch.+Headers%3A50650+Library%3A50528][/url]
Reply
#10

You have a mismatch with MySQLi try using a newer version of MySQLi and PHP.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB