Forum Moderators: coopster

Message Too Old, No Replies

mysql select db error!

         

nanewk

3:36 am on Mar 14, 2011 (gmt 0)

10+ Year Member



Here is the skinny - I can connect to my database just fine but when I try to access my table inside the database I keep getting thrown this error code:

Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in /var/www/clients/client11/web31/web/update.php on line 11

Here is my update.php code

<?php
$db_name = "X";
$db_pass = "X";
$db_user = "X";
$db_host = "localhost";

$con = mysql_connect($db_host,$db_user,$db_pass) || die(mysql_error());


$select = mysql_select_db('gold_market',$con) || die(mysql_error());

?>





Help. Please.

Demaestro

4:04 am on Mar 14, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Try

$select = mysql_select_db('select * from gold_market',$con) || die(mysql_error());

nanewk

4:17 am on Mar 14, 2011 (gmt 0)

10+ Year Member



Nope, same error :(

Matthew1980

9:50 am on Mar 14, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there nanewk,

<?php
$db_name = "gold_market";//<- assuming as db_name meant 'gold_market'
$db_pass = "X";
$db_user = "X";
$db_host = "localhost";

$con = mysql_connect($db_host,$db_user,$db_pass) or die(mysql_error());
$select = mysql_select_db($db_name,$con) or die(mysql_error());

?>

You were using the wrong operator, hopefully that will do as you ask now.

Cheers,
MRb

nanewk

5:30 pm on Mar 14, 2011 (gmt 0)

10+ Year Member



here is my code now:

$con = mysql_connect($db_host, $db_user, $db_pass);
if (!$con) {
die('Not connected : ' . mysql_error());
}

$select = mysql_select_db($db_table, $con);
if (!$select) {
die ('Table unavailable : ' . mysql_error());
}

And this is the error I am seeing:

Table unavailable : Access denied for user 'c11tgm'@'localhost' to database 'gold_market'

FYI - I am logged into phpMyAdmin with these credentials and I can run queries inside phpMyAdmin just fine.

nanewk

6:20 pm on Mar 14, 2011 (gmt 0)

10+ Year Member



FYI - I added the variable $db_table at the top which is not seen here.

Matthew1980

6:50 pm on Mar 14, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there,

<?php
error_reporting(E_ALL|E_DEPRECATED);

$db_name = "your_db_name_here";
$db_pass = "password_here";
$db_user = "username_here";
$db_host = "localhost";

$con = mysql_connect($db_host,$db_user,$db_pass) or die("Couldn't connect because:".mysql_error());
mysql_select_db($db_name,$con) or die("Couldn't select Db because:".mysql_error());
?>

Only thing that could go wrong now is typo's in the credentials that you use, this is virtually how I do mine, so I know as the code is correct.

Other than that; not too sure, long day and it's now beer o'clock!

Cheers,
MRb

nanewk

9:02 pm on Mar 14, 2011 (gmt 0)

10+ Year Member



I found my problem, was querying the TABLE and not the DATABASE in the select_db_name function..

Matthew1980

9:34 pm on Mar 14, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



^^^
That would explain it, I think that could qualify as a typo! Pleased that sorted out now anyway.

Cheers,
MRb

nanewk

10:09 pm on Mar 14, 2011 (gmt 0)

10+ Year Member



^^^
Or a newb mistake :D

Thanks for your help..