Home
Forums
Members
Search
Help
New topics
Todays topics
Website
Welcome Guest, Not a member yet?
Register
Sign In
Login
Username:
Password:
Remember me
Lost Password?
CodeIgniter Forums
Using CodeIgniter
General Help
Having trouble connecting to mysql database
Share on Google
Share on Facebook
Share on Twitter
View a Printable Version
Subscribe to this thread
Add Poll to this thread
Send thread to a friend
Linear Mode
Threaded Mode
Having trouble connecting to mysql database
vazaia
Newbie
Posts:
1
Threads:
1
Joined:
Nov 2020
Reputation:
0
#1
11-04-2020, 12:29 PM
Hello,
I want to connect MySQL community server, but I keep getting this error message over and over:
8
CodeIgniter\Database\Exceptions\DatabaseException #8
Unable to connect to the database.
This is the code:
$custom
= [
'DSN'
=>
''
,
'hostname'
=>
'localhost'
,
'username'
=>
'root'
,
'password'
=>
'root'
,
'database'
=>
'world'
,
'DBDriver'
=>
'MySQLi'
,
'DBPrefix'
=>
''
,
'pConnect'
=>
false,
'DBDebug'
=> (
ENVIRONMENT
!==
'production'
)
,
'cacheOn'
=>
false,
'cacheDir'
=>
''
,
'charset'
=>
'utf8'
,
'DBCollat'
=>
'utf8_general_ci'
,
'swapPre'
=>
''
,
'encrypt'
=>
false,
'compress'
=>
false,
'strictOn'
=>
false,
'failover'
=> []
,
'port'
=>
3306
,
]
;
$db
= \Config\Database::
connect
(
$custom
)
;
$db
->
query
(
"SELECT
*
FROM city"
)
;
$db
->
close
()
;
Any kind of help would be appreciated
Reply
InsiteFX
Super Moderator
Posts:
6,730
Threads:
344
Joined:
Oct 2014
Reputation:
246
#2
11-04-2020, 05:05 PM
And where are you calling the bottom database code?
Database code should be called from a model.
What did you Try?
What did you Get?
W
hat did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
Reply
--------------------
Private Messages
User Control Panel
Who's Online
Search
Forum Home
General
-- News & Discussion
-- Events
-- Lounge
-- Regional User Groups
Using CodeIgniter
-- Installation & Setup
-- Model-View-Controller
-- Libraries & Helpers
-- Best Practices
-- Choosing CodeIgniter
-- General Help
CodeIgniter 4
-- CodeIgniter 4 Roadmap
-- CodeIgniter 4 Development
-- CodeIgniter 4 Feature Requests
-- CodeIgniter 4 Support
-- CodeIgniter 4 Discussion
-- CodeIgniter 4 Addins
Development
-- CodeIgniter 3.x
-- CodeIgniter 2.x
-- Issues
-- NetBeans Plugin
External Resources
-- Spotlight
-- Learn More
-- Jobs
-- Addins
Archived Discussions
-- Archived Libraries & Helpers
-- Archived Development & Programming
Theme © iAndrew 2016 -
Forum software by © MyBB