Link to home
Start Free TrialLog in
Avatar of Soumen Roy
Soumen RoyFlag for India

asked on

Problem locating databases created from mysqli commands on PHP

Hello experts,

I am having a problem creating and selecting MySQL databases from my php script.

I have a fresh installation of Linux Debian 8, which came with an Apache 2 webserver installed. I connect to the server using the local IP of the server.

I installed the rest of the LAMP stack, PHP 7.0.12 and MySQL 5.5.2. Being a beginner in the Linux environment, I found the command line interface of MySQL quite intimidating. Hence I also installed MySQL workbench to create databases.

With all that done, I created two databases using Workbench that I needed for my sites. I am also a beginner in web programming and web development. Next I followed tutorials that show how to write simple PHP scripts and those worked. Then when I got into linking MySQL and PHP, things started going wrong.

Initially I had problem connecting to the database server using 'mysql_connect()', however, I found out after a bit of googling that mysqli_connect() is what works in PHP7. After the connection was successfully made, I created a Database using mysqli_query() from the PHP code, and also selected it using mysqli_select_db().

However, I could not select the databases I had initially created using workbench using mysqli_select_db(). I tried a lot of ways, like putting the php file and the db in the same folder, specifying the exact path of the db, but none worked. I am guessing it must be some problem regarding the location the php script looks at for finding the database.

Every tutorial I am looking into, uses some tool called PHPMyAdmin. Is it necessary to have PHPMyAdmin? From what I see, PHPMyAdmin is just a explorer and UI for working with databases, and so is workbench. So what is going missing here? The following are the things I would like to know:

1. Is there any way to specify to mysqli_select_db() to look for a database at a particular path/location?
2. What is the default location where the mysqli_##() commands look for or create databases at?
3. How to change this location?
4. What exactly does PHPMyAdmin do? What help would it be to use it?
5. Out of the context of MySQL and PHP, how to change the default webpage and the server directory of webpages of Apache 2 running on Linux?

Thanks in advance.
SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of arnold
arnold
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Soumen Roy

ASKER

Thank you for the response..

I have been using mysqli_error($conn) [$conn = mysqli_connect(#host:port, #user, #pass)], to look for errors, and that is how I found that the database I was looking for was not found, and that the full path does not work.. Now the codes work fine, and I keep using mysqli_error() as it turns out to be a very useful tool..

However, that does not solve my problem.. What I want to know is how to find out the path which phpmyadmin or the php scripts running on my webserver use to store and retrieve the databases?
Ythe path is available in show variables. When you create a db, it defaults to the system configured datadir.

I am uncertain what it is you are after.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
@Arnold Sorry for not being able to frame up my question good.
@skullnobrain's answers  were good enough.. I googled out some of those questions yesterday though..

Thanks for the assistance experts. :)