PDA

For continued disscussion on this topic : Problem connecting to mySQL database



BazzA
05-20-2001, 10:56 PM
hi all

A little while back I asked your advice on what route to take for web-databases. I ended up with PHP and mySQL (thank god for free stuff! :))

Admittedly I haven't done much with it since I decided what I wanted to do so I'm still messing around with the basics of database connectivity.

anyway....

here's the bit of code causing me grief:


$db_name = "2VAG";
$table_name = "_1015";

$con = @mysql_connect("main", "admin", "imgonnatellyou") || die ("Couldn't connect.");
echo $con;
$db = mysql_select_db($db_name, $con) || die ("Couldn't select database.");

even though the echo bit gives me a 1 (which is 'true', right?) I get this error when I run the code:



Warning: Supplied argument is not a valid MySQL-Link resource in C:/XITAMI/webpages/php/do_addrecord.php on line 13
Couldn't select database.

I can't see the problem with this simple piece of code. I can access the database fine though the mySQL console...

any ideas? am I being really silly?

thanks

BazzA

Arielladog
05-21-2001, 04:33 AM
Hey,

In mysql_connect, the first argument is your host. Is your host really "main" or was that just for the post...just make sure you have that correct. But it sounds like you do if it's returnning "1" (which is "true")

Now, the database name you are using is "2VAG" I hate to tell you, but database names can't start with numbers, so I think that's your problem.

aDog :cool:

BazzA
05-21-2001, 08:47 AM
The Xitami server defaults to http://main/ instead of the normal 'localhost' but it seems to work so I don't mind...

As to the numbers thing all is becoming clear. Its strange though, I created the 2VAG database through the mySQL console and it worked fine... so that looks like a bug-type thing to me... Thanks for bringing that to my attention!

Now I'm off to find out if I can rename a database or if I have to start all over (which admittedly isn't as bad as it sounds...)

Thanks!

BazzA


Grrr... my speeling 5uX0rz

BazzA
05-21-2001, 09:36 AM
hello again

I just went and made a new database 'VAG2' and moved the two tables I had into it. I modified the code to reflect this change but nothing seems to have changed...



$db_name = "VAG2";
$table_name = "_1015";

$con = @mysql_connect("main", "blokey", "whatever") || die ("Couldn't connect.");
echo $con;
$db = mysql_select_db($db_name, $con) || die ("Couldn't select database.");


Once again I get:



1
Warning: Supplied argument is not a valid MySQL-Link resource in C:/XITAMI/webpages/PHP/do_addrecord.php on line 13
Couldn't select database.


Surely this should be very simple!

BazzA
05-21-2001, 05:47 PM
I was experimenting with things and one of the things I tried was replacing the variable alias for the connection with the actual connection, as below:



$db = mysql_select_db("VAG2", mysql_connect("main", "adminman", "******")) || die ("Couldn't select database.");


this actually works, but will it cause problems as I start a new connection with every mySQL command sent through?

thanks

BazzA