How to Connect to remote MySQL database – PHP

  php

Q(Question):

Hello PHP group,

I have mysql running on a linux box. I have apache (2.0.4) running on a
diff linux box. I have php 4.X. I can connect to the mysql db using
odbc from a windows box, but cannot connect to the remote db from web
server box (linux) to mysql database (another linux box).
Apache is on RH Enterprise 3.0, mysql is on slacware (2.4.22 kernel).
I am using php, require_once(‘DB.php’),
and the dsn style connect string: "mysql://username:password@dbhost/test"

Always get an error :"unknown database"

How do I verify that my php is set for mysql?
and any ideas on why I cannot connect? PHP and Apache were the product
as it came with RH Enterprise 3.0ES. I have made no changes to PHP or
APACHE. Maybe I need to?

Thanks Again for the help i have received in the past from this group.

eric w. holzapfel

A(Answer):

Eric W. Holzapfel wrote:

and the dsn style connect string: "mysql://username:password@dbhost/test"

Always get an error :"unknown database"

Is that the full extent of the error message?

If you run a script like that shown below from the command line (i.e.
via php -f ) on the Linux system running PHP, what sort of output do you
get? Make sure you substitute the appropriate values for USERNAME,
PASSWORD, HOSTNAME, and DBNAME.

<?php

require_once( ‘DB.php’ );

$dsn = "mysql://USERNAME:PASSWORD@HOSTNAME/DBNAME";

$db_conn = DB::connect( $dsn );

if ( DB::isError( $db_conn ) ) {
print $db_conn->getDebugInfo( ) . "\n";

exit( 1 );
}
else {
print "Connected to database\n";
}

$db_conn->disconnect( );

?>

Lukas

A(Answer):

Lukas Neuburger wrote:

Eric W. Holzapfel wrote:

and the dsn style connect string: "mysql://username:password@dbhost/test"

Always get an error :"unknown database"

Is that the full extent of the error message?

If you run a script like that shown below from the command line (i.e.
via php -f ) on the Linux system running PHP, what sort of output do you
get? Make sure you substitute the appropriate values for USERNAME,
PASSWORD, HOSTNAME, and DBNAME.

<?php

require_once( ‘DB.php’ );

$dsn = "mysql://USERNAME:PASSWORD@HOSTNAME/DBNAME";

$db_conn = DB::connect( $dsn );

if ( DB::isError( $db_conn ) ) {
print $db_conn->getDebugInfo( ) . "\n";

exit( 1 );
}
else {
print "Connected to database\n";
}

$db_conn->disconnect( );

?>

Lukas

Hello PHP and Lukas,

It looks like I lose! I ran the above as "test.php" using php -f
test.php from the command line and got the following as output!
mysql://eric:dumbone@ewhslack/phpbook

What I got was the "echo" of the value for $dsn.
I will be checking my mysql on the slackware box, while I wait for a
reply from newsgroup!

Thanks,

eric

A(Answer):

Eric W. Holzapfel wrote:

Lukas Neuburger wrote:

Eric W. Holzapfel wrote:

and the dsn style connect string:
"mysql://username:password@dbhost/test"

Always get an error :"unknown database"

Is that the full extent of the error message?

If you run a script like that shown below from the command line (i.e.
via php -f ) on the Linux system running PHP, what sort of output do
you get? Make sure you substitute the appropriate values for USERNAME,
PASSWORD, HOSTNAME, and DBNAME.

<?php

require_once( ‘DB.php’ );

$dsn = "mysql://USERNAME:PASSWORD@HOSTNAME/DBNAME";

$db_conn = DB::connect( $dsn );

if ( DB::isError( $db_conn ) ) {
print $db_conn->getDebugInfo( ) . "\n";

exit( 1 );
}
else {
print "Connected to database\n";
}

$db_conn->disconnect( );

?>

Lukas

Hello PHP and Lukas,

It looks like I lose! I ran the above as "test.php" using php -f
test.php from the command line and got the following as output!
mysql://eric:dumbone@ewhslack/phpbook

What I got was the "echo" of the value for $dsn.
I will be checking my mysql on the slackware box, while I wait for a
reply from newsgroup!

Thanks,

eric

Yes, sadly it prints the $dsn variable only, no other info, nothing
comes out of the getDebugInfo( ) command. Could this command be wrong
for my version of php? I have php 4.3.2, I notice the php info in dbx
show mysql odbc, does this mean I may need to recompile php for mysql?
Thanks,

eric

A(Answer):

Eric W. Holzapfel wrote:

Yes, sadly it prints the $dsn variable only, no other info, nothing
comes out of the getDebugInfo( ) command. Could this command be wrong
for my version of php? I have php 4.3.2, I notice the php info in dbx
show mysql odbc, does this mean I may need to recompile php for mysql?
Thanks,

The getDebugInfo call is part of the the PEAR DB module, and should work
as long as DB is present and loaded. As to whether or not MySQL
support is enabled under PHP, the following commands should help answer
that:

1. php -i | grep -i mysql

2. php -m | grep -i mysql

These commands will tell you all about the level of MySQL support
available in your build of PHP. Try these commands out on your web
server system.

You will also find the following two links useful:

http://www.php.net/manual/en/ref.mysql.php
http://www.php.net/manual/en/ref.mysqli.php

These links not only discuss MySQL support in PHP, but also how to
enable MySQL support if you need to build your own copy of PHP.

Lukas

A(Answer):

Lukas Neuburger wrote:

Eric W. Holzapfel wrote:

Yes, sadly it prints the $dsn variable only, no other info, nothing
comes out of the getDebugInfo( ) command. Could this command be wrong
for my version of php? I have php 4.3.2, I notice the php info in dbx
show mysql odbc, does this mean I may need to recompile php for mysql?
Thanks,

The getDebugInfo call is part of the the PEAR DB module, and should work
as long as DB is present and loaded. As to whether or not MySQL support
is enabled under PHP, the following commands should help answer that:

1. php -i | grep -i mysql

2. php -m | grep -i mysql

These commands will tell you all about the level of MySQL support
available in your build of PHP. Try these commands out on your web
server system.

You will also find the following two links useful:

http://www.php.net/manual/en/ref.mysql.php
http://www.php.net/manual/en/ref.mysqli.php

These links not only discuss MySQL support in PHP, but also how to
enable MySQL support if you need to build your own copy of PHP.

Lukas

Hello Lukas,

Thanks for the info. I get quite a lot on the php -i | grep -i mysql
command. I get nothing for the php -m | grep -i mysql command –
(modules) I do get a ref to pear in the php -i area, a ref to mysql
shared. I will check the links, Thanks again

eric

A(Answer):

Hello Lukas et al,

Finally got it going. the modules, and other stuff was missing.
finally got the right pieces installed, etc.

Thanks for the help and info,

eric

Lukas Neuburger wrote:

Eric W. Holzapfel wrote:

and the dsn style connect string: "mysql://username:password@dbhost/test"

Always get an error :"unknown database"

Is that the full extent of the error message?

If you run a script like that shown below from the command line (i.e.
via php -f ) on the Linux system running PHP, what sort of output do you
get? Make sure you substitute the appropriate values for USERNAME,
PASSWORD, HOSTNAME, and DBNAME.

<?php

require_once( ‘DB.php’ );

$dsn = "mysql://USERNAME:PASSWORD@HOSTNAME/DBNAME";

$db_conn = DB::connect( $dsn );

if ( DB::isError( $db_conn ) ) {
print $db_conn->getDebugInfo( ) . "\n";

exit( 1 );
}
else {
print "Connected to database\n";
}

$db_conn->disconnect( );

?>

Lukas

LEAVE A COMMENT