DB connect

The following is what i did.

Do you mean I need to try the below?

I am running Ubuntu 19.04 and the inportant part of phpinfo() shows the following:

If that is not showing then I would remove/purge your current mysqli/mysql installation and follow this installation guide:

https://www.php.net/manual/en/mysqli.installation.php

Edit:
This maybe more appropriate to your system bcause “I installed Xubuntu 2 weeks ago”

Yup. That should install the mysqli extension to your PHP engine. You will then need to restart your apache service for the change to take effect.

(For those that follow: The only reason I could deduce for the “mysqli_connect function not defined” was Extension Not Installed. Fix Installation.)

1 Like

I think it works.
I need more test

Thank you, m_hutley, and John_Betong

1 Like

Now my new server has it “mysqli”.
Thank you, John_Betong.
.

1 Like

That’s great, but I would highly recommend you use PDO. This tutorial will get you going .

I had a look there, and I think the database name is optional, hence being in square-brackets. Also “If provided will specify the default database to be used when performing queries.” supports that.

The way I interpret the docs is all parameters are optional, most having the default come from the ini. The exception being the database name which defaults to an empty string.

That doesn’t make sense to me, AFAIK an empty string would not be a valid name. My guess is the “new connection” would use the same database as a currently unclosed connection. If so, because connections can close when the script terminates I don’t imagine taking advantage of this behavior would be that common. IMHO, even if not technically required, for all practical purposes it might as well be.

It’s possible to establish a connection to a database server without predefining which database you want to use.

It’s just shorthand, and most users of a database server only operate on a single database.

Consider something like phpMyAdmin - it doesnt know what database the root user wants to operate on, which is why it presents the list of databases - it doesnt need to connect to any specific database from the get-go.

I think that’s what I was thinking of - when I started looking at PHP, the samples I was reading would connect to the database server, and then separately select the database. I can’t say whether I still do it that way - the database connection code is in a separate include file, and whenever I start something new I just copy one of them and change the details.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.