Help connecting to a DB again

Problems with the Windows version of XAMPP, questions, comments, and anything related.

Help connecting to a DB again

Postby dgkindy » 13. October 2019 04:42

It has been a few years since I had my site up and running and have forgotten much since then as well. I have reinstalled XAMPP on my computer to get everything running again but can't access the db and looking for some help.

I have the following piece of code that runs down to the last line indicating that it can't use the db petdb.
Code: Select all
<?php
//connect to database server
$link = mysqli_connect('localhost', $INFO['user_name'], $INFO['user_pswd']);
//print'hello';
//$link = mysqli_connect('localhost','davidkindy', 'dk&hk');
//print'hello1';

if (!$link) die('Could not connect to Database Server: '.mysql_error());


// make petdb the current db
$db_selected = mysqli_select_db('petdb', $link);
if (!$db_selected) die ('Can\'t use database petdb : '.mysqli_error());
?>


I have this code that provides the login detail.
Code: Select all
<?php
$INFO['user_name'] = 'davidkindy';
$INFO['user_pswd'] = 'dk&hk';
?>


In the accounts overview, I have created an account davidkindy with hostname as localhost and %. There is a DB called petdb created.
dgkindy
 
Posts: 6
Joined: 13. October 2019 04:34
XAMPP version: 3.2.4
Operating System: windows 10

Re: Help connecting to a DB again

Postby Altrea » 13. October 2019 15:05

Does this database user have permissions to access this database?
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 9856
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 10 Pro x64

Re: Help connecting to a DB again

Postby dgkindy » 13. October 2019 16:21

In the accounts overview of phpMyAdmin, I have created an account davidkindy with hostname as localhost and % and I have set the password as shown above.
dgkindy
 
Posts: 6
Joined: 13. October 2019 04:34
XAMPP version: 3.2.4
Operating System: windows 10

Re: Help connecting to a DB again

Postby Altrea » 13. October 2019 18:40

Yes, but which global or database permissions does this user have?
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 9856
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 10 Pro x64

Re: Help connecting to a DB again

Postby dgkindy » 14. October 2019 16:12

phpMyAdmin indicates all privileges.
dgkindy
 
Posts: 6
Joined: 13. October 2019 04:34
XAMPP version: 3.2.4
Operating System: windows 10

Re: Help connecting to a DB again

Postby Altrea » 14. October 2019 18:15

What is the full error message you get?
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 9856
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 10 Pro x64

Re: Help connecting to a DB again

Postby dgkindy » 14. October 2019 20:57

It just indicates "Can't use database petdb :"
but this is simply the result of the if statement in the code


Code: Select all
if (!$db_selected) die ('Can\'t use database petdb : '.mysqli_error());
dgkindy
 
Posts: 6
Joined: 13. October 2019 04:34
XAMPP version: 3.2.4
Operating System: windows 10

Re: Help connecting to a DB again

Postby dgkindy » 14. October 2019 22:13

Not sure if this makes any difference or not but just in case. I noted that my localhost is actually localhost:8080 so I created an account with that login but still no luck.
dgkindy
 
Posts: 6
Joined: 13. October 2019 04:34
XAMPP version: 3.2.4
Operating System: windows 10

Re: Help connecting to a DB again

Postby Altrea » 15. October 2019 01:05

mysqli_error() needs to get the db link as parameter to return a detailed error message. So let's start there.
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 9856
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 10 Pro x64

Re: Help connecting to a DB again

Postby cb » 15. October 2019 19:49

Hi there

I think you have the parameters in the wrong order in the mysqli_select_db statement.

Code: Select all
$db_selected = mysqli_select_db('petdb', $link);


should be

Code: Select all
$db_selected = mysqli_select_db($link, 'petdb');


You should also be able to specify the db in the connect statement and then remove the db_selected statement.

Code: Select all
$link = mysqli_connect('localhost', $INFO['user_name'], $INFO['user_pswd', 'petdb']);


Good luck
cb
cb
 
Posts: 19
Joined: 11. June 2008 22:48

Re: Help connecting to a DB again

Postby dgkindy » 16. October 2019 04:24

That seems to be helping and making progress.

Is the new syntax for MySQL now mysqli?

At this point, I need to go through all my code and update everything with mysqli?
dgkindy
 
Posts: 6
Joined: 13. October 2019 04:34
XAMPP version: 3.2.4
Operating System: windows 10

Re: Help connecting to a DB again

Postby Nobbie » 16. October 2019 09:29

dgkindy wrote:At this point, I need to go through all my code and update everything with mysqli?


Yes. The mysql extension is deprecated since PHP 5.5.0 and has been removed in PHP 7.
Nobbie
 
Posts: 11211
Joined: 09. March 2008 13:04

Re: Help connecting to a DB again

Postby JJ_Tagy » 16. October 2019 17:12

dgkindy wrote:At this point, I need to go through all my code and update everything with mysqli?

If you write it into a class or common function, you only need to change it once.
JJ_Tagy
 
Posts: 764
Joined: 30. January 2012 13:44
Operating System: Windows 10 Pro x64


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 33 guests