PDA

View Full Version : PHP connecting to MySQL on 2.0



mindseye
09-05-2003, 10:42 AM
Ok, I'm not getting any timely help from tech support...probably becuase they are trying figure out why on earth they implemented 2.0...oh well.

I have a new account that was originally set up on 2.0 (not transfered from 1.0). I installed MySQL and PhpMyAdmin, and all that was running fine. However, once I created my own PHP scripts and tried to execute them, it always errors out: 'No Database Selected'. I am using the following string to connect (the same one that WH recommends):

mysql_connect('localhost','user','pass');
@mysql_select_db("mydb");
This is the same string I am using on many other sites, both on 1.0 and 2.0...all working fine.

I have submitted 2 different support tickets, but are not resolved yet, the only 'help' that I have received so far is...

On our old setup you were not the administrator of your database and so using your username and password automatically selected the appropriate database to use. Now things have changed and with WestHost 2.0 you administer your db, which means you have a choice of which to use. Make sure you are using the mysql_select_db() function in your code after the mysql_connect and before you do any queries.

I am doing everything that was suggested here (which I told tech support) but I am still getting the same error...and waiting for a tech support reply. If anyone can help me figure this out, I'll give you a cookie (WH tech support not eligible for prize).

mindseye
09-05-2003, 12:29 PM
Ok, I found the answer on another post. Thank you design64!

Just in case anyone else has this same problem at the moment you're reading this, here's the solution:


mysql_connect('localhost',root,'password');
@mysql_select_db("databasename");

Be sure not to enclose root in quotes. Also, your password is obviously the mysql password, not your WH account password.

To all you coders who are probably shaking your heads at this elementary discovery, go treat yourself to a box of Krispy Kreams and a large Mt. Dew. :D

Henning
09-08-2003, 04:57 PM
Ok, I found the answer on another post. Thank you design64!

Just in case anyone else has this same problem at the moment you're reading this, here's the solution:


mysql_connect('localhost',root,'password');
@mysql_select_db("databasename");

Be sure not to enclose root in quotes. Also, your password is obviously the mysql password, not your WH account password.

To all you coders who are probably shaking your heads at this elementary discovery, go treat yourself to a box of Krispy Kreams and a large Mt. Dew. :D

WHAT ??? Do I have to change to root in all my scripts?
What have I missed?

ajparker
09-08-2003, 05:51 PM
You could of course, also add another user with phpmyadmin.

Avery

REC-WH
09-08-2003, 07:28 PM
[quote="Henning"][quote="mindseye"]Ok, I found the answer on another post. Thank you design64!

Just in case anyone else has this same problem at the moment you're reading this, here's the solution:


mysql_connect('localhost',root,'password');
@mysql_select_db("databasename");

Be sure not to enclose root in quotes. Also, your password is obviously the mysql password, not your WH account password.
quote]

I would like to thanks you for the post! You are right! This solve my problems of creating DB with PHP. This is my script setup below.

$db_user = root;
$db_password = 'your password';
$db_database = 'yourdasebase';
$db_server = 'localhost'; //database server -- usually localhost, but one never knows

If you can't find your DB looking in /var/lib/mysql/.

I think the WH2 Control Panel has great potential! It is sad that the conversion went go bad!

THANK AGAIN FOR THE POST!

CM

nwest
09-09-2003, 09:16 AM
I tried the new syntax for connecting to mysql, and several other variations, but I still keep getting the same error.

Warning: mysql_connect() [function.mysql-connect]: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

I'm not sure why it is I cannot connect through php, but I can connect using the command line both with and without specifying passwords and usernames.

mdueri
09-11-2003, 02:30 AM
from the command line I connect fine using the new password, but from php, I have to use the old password! and even so, my INSERT INTO does not work. I can only SELECT. Anyone having similar issues? This is really getting frustrating since I was hoping to get my site up on monday. I wish they would have tested this thing before moving it over.

FZ
09-11-2003, 04:54 AM
I heard someone say my name! :P I'm glad my post helped you, mindseye.

mdueri,

You should install PhpMyAdmin like Avery pointed out. It will allow you to add username/password combos very easily.

About the passwords being different, I think that is related to the issue of (now) having to use root as username. Try that - username: root, and the new password. The reason your old one still works is probably because WestHost added it to make sure your old scripts did not break, and the reason it can only select is because WestHost made it do that on purpose - mySQL privilages. It's all in PhpMyAdmin if you take a look.

MattJ
09-11-2003, 05:17 AM
We were using a PHP/mySQL driven system before the switchover. Our db got clobbered and PHPmyAdmin couldn't connect to it. Westhost has since restored the db and things seem to be working again.

Is there any reason for me to re-install PHPmyAdmin via the Manager so I have a standard directory structure for it? Or would that be nuts given our 5-day off-line last week?

-Matt

FZ
09-11-2003, 02:31 PM
PhpMyAdmin is terribly useful. And you have nothing to lose - installing PhpMyAdmin will not affect your database. The worst case scenario is it (PhpMyAdmin) does not work. But since you would be installing it through the Site Manager, it will work for sure...

The point is, if you need a GUI/admin tool for your database, then install and use it. If not, then there is no point.

mdueri
09-11-2003, 04:23 PM
I changed my password and everything works now. I still haven't heard from support and its been 3 days. I'm glad you were kind enough to answer my question or I'd be screwed.
:lol:

FZ
09-11-2003, 06:25 PM
You're welcome - I'm glad you got it sorted out, mdueri.