mysql_select_db() and mysql_query()

mysql_select_db() and mysql_query()

am 29.11.2002 21:20:22 von dan martin

A friendly error message advised me that "mysql_db_query" is deprecated and
to use "mysql_select_db() and

mysql_query()". but I can't seem to get past this return in the Browser:
"Parse error: parse error in c:\program files\apache

group\apache\htdocs\crup_hs_local\result.php on line 58". I think I don't
understand the basic syntax.

/*$result = mysql_db_query($dbname,$sql);*/
/*mysql_db_query is deprecated; use mysql_select_db() and mysql_query()*/
$result = mysql_select_db($dbname) or die(mysql_error();
$result = mysql_query($sql);
$numrows = mysql_num_rows($result);

I've search my references and the PHP Manual, but can't seem to figure this
out. I'd be grateful for a reference or guidance.

Thanks,

Dan




--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: mysql_select_db() and mysql_query()

am 29.11.2002 23:09:37 von Beth Gore

Hi Dan,

Dan Martin wrote:

>group\apache\htdocs\crup_hs_local\result.php on line 58". I think I don't
>understand the basic syntax.
>
>/*$result = mysql_db_query($dbname,$sql);*/
>/*mysql_db_query is deprecated; use mysql_select_db() and mysql_query()*/
>$result = mysql_select_db($dbname) or die(mysql_error();
>$result = mysql_query($sql);
>$numrows = mysql_num_rows($result);
>
>
A valid database connection, open and query is as follows:

/* connect to the server, and assign the connection to $Conn */
$conn = mysql_connect("mysqlserver","myusername","mypassword") or
die("Could not connect");

/* select a database using $conn as the connection */
mysql_select_db($conn) or die("Unable to Connect");

/* a SQL query we'd like to make */
$SQL = "SELECT * FROM foobar";

/* get a record set from the mySQL database using the SQL query, and put
the data in $rs */
$rs = mysql_query($SQL);

/* get a row of data from $rs, and assign it to $foo_row */
$foo_row = mysql_fetch_array($rs);

/* print out some of the stuff from $foo_row */
echo foo_row['foo'];
echo foo_row['bar'];


The parse error you got comes from the 'or die(mysql_error();' bit.. you
forgot the final closing bracket, i.e. it should have been:

die( mysql_error() );

Have another go! It's one of those things you only ever write once, and
just cut and paste it for everything you ever do ever again!

Beth Gore


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RE: mysql_select_db() and mysql_query()

am 30.11.2002 22:11:14 von John Holmes

> A friendly error message advised me that "mysql_db_query" is
deprecated
> and
> to use "mysql_select_db() and
>
> mysql_query()". but I can't seem to get past this return in the
Browser:
> "Parse error: parse error in c:\program files\apache
>
> group\apache\htdocs\crup_hs_local\result.php on line 58". I think I
don't
> understand the basic syntax.
>
> /*$result = mysql_db_query($dbname,$sql);*/
> /*mysql_db_query is deprecated; use mysql_select_db() and
mysql_query()*/
> $result = mysql_select_db($dbname) or die(mysql_error();

You're missing a closing parenthesis on the above line.

---John Holmes...



--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: mysql_select_db

am 20.10.2008 22:19:42 von Stut

On 20 Oct 2008, at 13:03, Stan wrote:
> UBUNTU Server v8.04
> On a web page:
>
> CODE:
> require_once 'frames_includes/navigationDB.inc';
> $navigation_connection = mysql_connect($navigation_hostName,
> $navigation_userName,
> $navigation_passWord)
> or
> die("Failed to connect to MySQL on the nasServer ... call Stan");
> mysql_select_db($navigation_databaseName,$navigation_connect ion)
> or
> die("Selection of 'navigation' database failed ... call Stan");
> $navigation_data = mysql_query("SELECT * FROM " .
> $navigation_databaseName . ".navigate " .
> "ORDER BY navigateHandle",
> $navigation_connection)
> or
> die("SELECT * FROM navigate table failed ... call Stan");
> END CODE:
>
> works when the UBUNTU server is attached to the same subnet as the
> MySQL
> server.
>
> If I move the UBUNTU server to a different subnet (through an ipCop
> machine), making appropriate adjustments to network configuration,
> including
> punching a hole in the firewall for port 3306 from the UBUNTU server
> to the
> MySQL server and authorizing the user at the new IP to MySQL, the
> mysql_connect works but the mysql_select_db fails.
>
> I need help debugging this, please?

MySQL permissions are tied to IP or hostname as well as username and
password. Sounds like the user you're connecting as has different
permissions when it comes from a different subnet. Check the MySQL
manual for detailed info on permissions.

-Stut

--
http://stut.net/

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: mysql_select_db

am 21.10.2008 13:11:17 von Stan

My include, navigationDB.inc, contains:

CODE:
$navigation_hostName = "nasServer";
$navigation_databaseName = "navigation";
$navigation_userName = "stan";
$navigation_passWord = "password";
?>
END CODE:

(no change) and I added an instance of that user with that password at the
new IP address on the MySQL server before testing.

Hmmm ...

but what I didn't do was restart MySQL.



--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: mysql_select_db

am 21.10.2008 13:26:01 von Stan

Nope ... that wasn't it.

The mysql_connect() works.

It's the mysql_select_db() that's failing.



--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: mysql_select_db

am 21.10.2008 17:18:54 von Micah Stevens

Try it on the command line from the webserver:

mysql -h hostname -u Stan -p Password

See if that connect works.

-Micah

On 10/21/2008 04:26 AM, Stan wrote:
> Nope ... that wasn't it.
>
> The mysql_connect() works.
>
> It's the mysql_select_db() that's failing.
>
>
>
>

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: mysql_select_db

am 21.10.2008 20:06:10 von Stan

------=_NextPart_000_000A_01C9337D.CC66FD80
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

So ... if I enter "mysql -h mysqlServer -u stan -p" and then enter the =
password, I get connected without a problem ... I get the mysql client =
prompt.

And the mysql_connect() statement in my code does not "die".

But the mysql_select_db() statement in my code does "die".

"Micah Stevens" wrote in message =
news:48FDF2DE.60306@raincross-tech.com...
> Try it on the command line from the webserver:
>=20
> mysql -h hostname -u Stan -p Password
>=20
> See if that connect works.
>=20
> -Micah
>=20
> On 10/21/2008 04:26 AM, Stan wrote:
> > Nope ... that wasn't it.
> >
> > The mysql_connect() works.
> >
> > It's the mysql_select_db() that's failing.
> >
> >
> >
> >
------=_NextPart_000_000A_01C9337D.CC66FD80--

Re: mysql_select_db

am 21.10.2008 21:12:25 von Micah Stevens

Okay, on the command line, then connect, and then select your database,
what's the error message it gives?

-Micah

On 10/21/2008 11:06 AM, Stan wrote:
> So ... if I enter "mysql -h mysqlServer -u stan -p" and then enter the password, I get connected without a problem ... I get the mysql client prompt.
>
> And the mysql_connect() statement in my code does not "die".
>
> But the mysql_select_db() statement in my code does "die".
>
> "Micah Stevens" wrote in message news:48FDF2DE.60306@raincross-tech.com...
>
>> Try it on the command line from the webserver:
>>
>> mysql -h hostname -u Stan -p Password
>>
>> See if that connect works.
>>
>> -Micah
>>
>> On 10/21/2008 04:26 AM, Stan wrote:
>>
>>> Nope ... that wasn't it.
>>>
>>> The mysql_connect() works.
>>>
>>> It's the mysql_select_db() that's failing.
>>>
>>>
>>>
>>>
>>>

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: mysql_select_db

am 21.10.2008 23:42:48 von dmagick

Stan wrote:
> So ... if I enter "mysql -h mysqlServer -u stan -p" and then enter the password, I get connected without a problem ... I get the mysql client prompt.

You haven't selected a db.

Inside mysql:

use database_name;

> And the mysql_connect() statement in my code does not "die".
>
> But the mysql_select_db() statement in my code does "die".

What error?

echo mysql_error();


--
Postgresql & php tutorials
http://www.designmagick.com/


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php