CodeIgniter Forums
Database access version 4 doesn't work - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Database access version 4 doesn't work (/showthread.php?tid=77221)



Database access version 4 doesn't work - AverageGuy - 08-03-2020

I mean I'm not able to get it to work.  I configured a database access in Database.php using known database parameters and then tossed a
Code:
$db = \Config\Database::connect();
Into my controller, and got a Whoops!
My question is where do I find a log that tells me what went wrong?

I put a try/catch around it, but that didn't help.
Thanks,
Jim.


RE: Database access version 4 doesn't work - jreklund - 08-03-2020

Error logs are in the /writable/logs folder.
https://codeigniter.com/user_guide/installation/troubleshooting.html#what-s-with-an-unhelpful-whoops-page


RE: Database access version 4 doesn't work - paulbalandan - 08-03-2020

First copy the env file to .env
cp env .env

Then open '.env' and change the value of CI_ENVIRONMENT to development.

The logs should be in writable/logs folder if you haven't changed anything yet.


RE: Database access version 4 doesn't work - AverageGuy - 08-03-2020

(08-03-2020, 08:13 AM)jreklund Wrote: Hi, take a look at this tutorial:
https://forum.codeigniter.com/thread-76777.html

And instead of /public_html/ it should be /public_html/edit

And you need ../../ instead of ../ in your index.php file.

If it dosen't work, open up your .htaccess and only change "RewriteBase /edit", everything else should be left as is.

(08-03-2020, 12:29 PM)paulbalandan Wrote: First copy the env file to .env
cp env .env

Then open '.env' and change the value of CI_ENVIRONMENT to development.

The logs should be in writable/logs folder if you haven't changed anything yet.

Thanks, I found the problem. There's this really, really bad feature of version 4.
"Not all of the drivers have been converted/rewritten for CodeIgniter4. The list below shows the outstanding ones."
And Mysql/PDO is in that list. Since I am porting code written for version 3, I'm screwed.

I just wasted a day, but then I'm much more familiar with V3 so I'll be more productive from now on.

Thanks to you all. I suspect I won't have many other questions now that I will start over with V3.

Jim.


RE: Database access version 4 doesn't work - jreklund - 08-03-2020

We have support for mysqli, you won't notice any difference to PDO MySQL driver.


RE: Database access version 4 doesn't work - AverageGuy - 08-03-2020

(08-03-2020, 12:42 PM)jreklund Wrote: We have support for mysqli, you won't notice any difference to PDO MySQL driver.
Good point, the code I'm porting over uses mostly CI access.  Some of what I'm not bringing over uses direct PDO calls, since I never was able to do some things with CI database access. So guess I'm not as screwed as I thought.

Thanks,Jim


RE: Database access version 4 doesn't work - jreklund - 08-03-2020

There are nothing stopping you from using PDO outside of CodeIgniter database library. Those listed in the documentation are what CodeIgniter database library can connect to.

I'm just guessing that you mean plain queries when you mean PDO right? That you used $this->db->query? Are that what you mean by PDO?
If so, you can still do all those things, but with the mysqli driver.


RE: Database access version 4 doesn't work - AverageGuy - 08-03-2020

(08-03-2020, 01:32 PM)jreklund Wrote: There are nothing stopping you from using PDO outside of CodeIgniter database library. Those listed in the documentation are what CodeIgniter database library can connect to.

I'm just guessing that you mean plain queries when you mean PDO right? That you used $this->db->query? Are that what you mean by PDO?
If so, you can still do all those things, but with the mysqli driver.
Now that I get to looking at the code, it seems I converted all the PDO calls to CI style calls.  I forgot about that.  I wrote this about 4 years ago and for various reasons, the folks I wrote it for dumped it after a year, so I haven't looked at it for a while.  I have a new project and am stealing some of the logic and views from that older project.  I guess my concerns aren't all that important any longer.

Thank you for your help.
Jim.