Connecting Tech Pros Worldwide Forums | Help | Site Map

mysql_connect succeeds but select_db fails

Jared
Guest
 
Posts: n/a
#1: Jul 17 '05
This is very strange.

I'm running MySQL 4.1.10, and php 4.3.10, on a FreeBSD 4.10 box. The
database has been created, and permissions are set right. I can access
the database from bin/mysql without a problem, too, using -uweb
-pblahblahblah.

<?php

$connection = @ mysql_connect("localhost", "web", "blahblahblah") ||
die( mysql_error());

printf("conn = %d<p>", $connection);

mysql_select_db("somedb", $connection) || die (mysql_error() );

?>

which yields:

conn = 1

Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link
resource in /usr/local/apache8001/htdocs/scratch/index.php on line 7

I am so at a loss, and could use any help you could offer.


Andy Hassall
Guest
 
Posts: n/a
#2: Jul 17 '05

re: mysql_connect succeeds but select_db fails


On 20 Feb 2005 06:16:17 -0800, "Jared" <jared.t.boehm@gmail.com> wrote:
[color=blue]
>This is very strange.
>
>I'm running MySQL 4.1.10, and php 4.3.10, on a FreeBSD 4.10 box. The
>database has been created, and permissions are set right. I can access
>the database from bin/mysql without a problem, too, using -uweb
>-pblahblahblah.
>
><?php
>
>$connection = @ mysql_connect("localhost", "web", "blahblahblah") ||
>die( mysql_error());[/color]

Actually you probably want the 'or' operator - not ||. There's a subtle
difference related to operator precedence.

$connection = @mysql_connect("localhost", "web", "blahblahblah")
or die(mysql_error());

http://uk.php.net/manual/en/language...ors.precedence
[color=blue]
>printf("conn = %d<p>", $connection);
>
>mysql_select_db("somedb", $connection) || die (mysql_error() );
>
>which yields:
>
>conn = 1[/color]

Should have been something like 'MySQL Link Resource #1'- but you'd have to
use %s in the format string anyway.
[color=blue]
>Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link
>resource in /usr/local/apache8001/htdocs/scratch/index.php on line 7
>
>I am so at a loss, and could use any help you could offer.[/color]

--
Andy Hassall / <andy@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Frank East
Guest
 
Posts: n/a
#3: Jul 17 '05

re: mysql_connect succeeds but select_db fails


On 2005-02-20 09:16:17 -0500, "Jared" <jared.t.boehm@gmail.com> said:
[color=blue]
> This is very strange.
>
> I'm running MySQL 4.1.10, and php 4.3.10, on a FreeBSD 4.10 box. The
> database has been created, and permissions are set right. I can access
> the database from bin/mysql without a problem, too, using -uweb
> -pblahblahblah.
>
> <?php
>
> $connection = @ mysql_connect("localhost", "web", "blahblahblah") ||
> die( mysql_error());
>
> printf("conn = %d<p>", $connection);
>
> mysql_select_db("somedb", $connection) || die (mysql_error() );
>
> ?>
>
> which yields:
>
> conn = 1
>
> Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link
> resource in /usr/local/apache8001/htdocs/scratch/index.php on line 7
>
> I am so at a loss, and could use any help you could offer.[/color]

You do want to use 'or' and also be certain that you've granted rights
to the user you are logging in as to access and do stuff with that
database...

Closed Thread