mysqli_connect database (4th) argument

Codes here !

Moderators: macek, egami, gesf

bobg
New php-forum User
New php-forum User
Posts: 3
Joined: Thu Oct 11, 2012 2:14 pm

mysqli_connect database (4th) argument

Postby bobg » Thu Oct 11, 2012 2:40 pm

I used MySQL Workbench to define a table - so I have to have defined a database right? But I cannot figure out the name of the database to use for the 4th argument to mysqli_connect. I have the "EER Model" (jdmacdo_MHLendingLibrary) but that didn't work. The "Model Overview" shows something called a "Physical Schemata" (although maybe it's called a "MySQL Schema") named "mydb" (although I don't think I ever entered that name) and that doesn't work either. Attached is a screenshot of the MySQL Workbench page which shows the Model Overview.

Can anyone tell me where I can find what I need for the database argument to mysqli_connect?

Thanks, Bob
Attachments
ModelOverview.png
ModelOverview.png (94.57 KiB) Viewed 493 times

seandisanti
php-forum Fan User
php-forum Fan User
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: mysqli_connect database (4th) argument

Postby seandisanti » Thu Oct 11, 2012 2:52 pm

mydb is the name of your database.

bobg
New php-forum User
New php-forum User
Posts: 3
Joined: Thu Oct 11, 2012 2:14 pm

Re: mysqli_connect database (4th) argument

Postby bobg » Thu Oct 11, 2012 6:27 pm

Thank you Sean. That makes sense. But the error message is:

ERROR: mysqli_connect(): (42000/1049): Unknown database 'mydb'

The mysqli_connect statement is:

@ $db = mysqli_connect('localhost', 'root', 'xxxxxxxxx', 'mydb');

I am sure I never defined a user other than 'root'.

Does the following help:

mysql> show schemas;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sakila |
| test |
| world |
+--------------------+
6 rows in set (0.00 sec)

mysql> show grants;
+-------------------------------------------------------------------------------
---------------------------------------------------------+
| Grants for root@localhost
|
+-------------------------------------------------------------------------------
---------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '*9EF
FBAB869ED6CE2461D6AB5D2A531649985FB67' WITH GRANT OPTION |
| GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION
|
+-------------------------------------------------------------------------------
---------------------------------------------------------+
2 rows in set (0.00 sec)

I will appreciate any further help.

Thanks, Bob

bobg
New php-forum User
New php-forum User
Posts: 3
Joined: Thu Oct 11, 2012 2:14 pm

Re: mysqli_connect database (4th) argument

Postby bobg » Thu Oct 11, 2012 6:35 pm

Well apparently the database is "mysql". I tried that because it was shown as one of the databases in the output of the show schemas; command. But I don't know where it came from (maybe it's a default name?) and don't know how I could have known that from the Workbench.

Sean, thanks again for your interest and help.

Bob

seandisanti
php-forum Fan User
php-forum Fan User
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: mysqli_connect database (4th) argument

Postby seandisanti » Fri Oct 12, 2012 8:30 am

There is a default database of mysql, i don't know if you necessarily want to use that one for your data but someone smarter than me can tell you the pros and cons on that one. if you'd already created tables etc that you were intending to use, you can also do

mysql>use test;
Database changed
mysql>show tables;

to see the list of tables in a database


Return to “mySQL & php coding”

Who is online

Users browsing this forum: No registered users and 1 guest