LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   cannot connect to mysql database (https://www.linuxquestions.org/questions/linux-software-2/cannot-connect-to-mysql-database-204858/)

mrosati 07-14-2004 07:06 AM

cannot connect to mysql database
 
hi.
i have installed fedora core 2. i have working php and apache on, but mysql give me some problems:
i can connect to the mysql server with the command "mysql_connect();" but when i try to connect to a database "mysql_select_db("database");" i get a FALSE result.
the scritp that i have tried to use is this:

/*terminal*/
mysql> CREATE DATABASE pippo;
Query OK, 1 row affected (0.00 sec)
/***********/

<?
if(!mysql_connect("localhost", "", ""))
die("CONNECTION TO MYSQL FAILED<br>");
else
echo"CONNECTED SUCCESSFUL TO MYSQL<br>";


if(!mysql_select_db("pippo"))
die("DATABASE SELECTION FAILED<br>");
else
echo"SUCCESSFUL SELECTED DATABASE<br>";
?>

the code is ok, i have tried it on windows and it works.

thank you.

Matteo

BluePyre 07-14-2004 09:18 AM

Maybe you need something in the database?

Can you do something like this and tell me what error message you get:

mysql_select_db("pippo") or die(mysql_error());

mrosati 07-14-2004 10:15 AM

hi
the error i get using that line of code is:

Access denied for user: '@localhost' to database 'pippo'

maybe i have to set some config files?

thank you so much

Matteo

BluePyre 07-14-2004 02:00 PM

Are you sure that worked on Windows? It looks like you forgot to pass the id of the mysql_connect command to the mysql_select_db in the arguments for it, like so:

$db_id = mysql_connect("localhost","","");
mysql_select_db("pippo",$db_id);

I'm not sure if it works otherwise.
If that doesn't work, try setting a username and password for mysql.

Good luck

mrosati 07-14-2004 02:10 PM

hm...
i have solved the problem setting a username for the database with the command "mysql_permissions" (or something similar) form the shell and connecting to mysql using that username and connecting to that database... but i don't understand WHY on windows i can create select delete databases without setting anything.... really windows is easier than linux...maybe for my work i will use windowd to develop my pages!

thx Matteo

BluePyre 07-14-2004 02:43 PM

I don't think thats a particularly useful feature... More unsafe than anything

mrosati 07-15-2004 04:10 AM

i have copmpletely solved my problem:
to create databases freely i have to log to the mysql server as "root" user (mysql_connect("localhost", "root", "")) and then i am free to do what i want...

BluePyre 07-15-2004 05:43 AM

I'm still curious as to how that worked, as you didn't pass the id of the mysql_connect command. Does it automagically use the last database you connected to?

mrosati 07-15-2004 06:30 AM

yes. if you don't specify any db_id, it uses the last db you referred to. you can also check it on

http://php.it/manual/it/function.mysql-select-db.php (italian)
http://www.zend.com/manual/function.mysql-select-db.php (english)

but i still dont understand WHY on linux i have to connect to mysql as "root" (mysql_connect("localhost", "root", "")) and in windows is not necessary to specify to connect with root user...

BluePyre 07-15-2004 06:37 AM

Thanks for the link.
Maybe not specifying a username on windows is equivalent to specifying root on linux? It was probably advised against allowing a no-user no-pass system for MySQL on Linux.

mrosati 07-15-2004 06:47 AM

yes maybe... surely linux is safer than windows...in fact if i should put the php site i have developed (very simple..but hey man, i have started studying php one week ago..!) on my machine as a server with windows everybody could create databases or delete them...and that's not good!

BluePyre 07-15-2004 06:56 AM

*nods*
PHP is easy if you have background programming knowledge from any of the C family of languages. It's definitely the number one time saver.

mrosati 07-15-2004 07:05 AM

what do you think about ASP?

BluePyre 07-15-2004 08:02 AM

Well, put simply, a common way to interface with ASP is VBScript, and there's no way i'm going to design a site that only works with Internet Explorer.
I admit I haven't used ASP much, but from what i've read and been told, it allows for the same usage as PHP.
I prefer linux servers for my websites as well as they normally have Cron, g++, and other useful programs, which means no chance for it.

Plus I like my semi colons and my dollar symbols :)

mrosati 07-15-2004 08:23 AM

i think the same as you...but usually using linux servers and php is synonimous of "hard"...people think "why i have to spend hours to do a thing on linux when i can do it spending 5 minutes on windows? it's the price to pay for more security...
one more thing:
(for example)
i work for a company who produces php sites. someone tells me to develop a site that interacts with mysql. when i write the site i have to suppose that the databases i will use are already created (by the server administrators) or it is my duty to create databases with my scripts? in other words, it is the programmer's duty to create databases or he has only to interact with these?

maybe you have more experience in this and you can explain how does it work!

thank you

Matteo


All times are GMT -5. The time now is 12:16 AM.