Jump to content

Remote MySQL php


Recommended Posts

Hello,

 

I have php and mysql installed:

 

PHP 5.1.6 (cli) (built: Jul 16 2008 19:52:52)

MySQL 5.0.45

 

MySQL is running on a remote server.  I wrote a simple php script to test connectivity and the connection keeps failing.  The firewall ports are open to 3306 and I am able to use the mysql client from the remote system fine.  Also, if I run the script:

 

php ./connect.php

 

This command returns a successful connection.  Do anyone know why php can connect to MySQL from the command-line, but not from a web server?

 

If you have any insight, please let me know.

 

-Phibertek

Link to comment
Share on other sites

Do anyone know why php can connect to MySQL from the command-line, but not from a web server?

 

Have you granted permissions for the user to connect from a remote host? eg;

 

GRANT ALL PRIVILEGES ON dbname TO 'username'@'remotehost' IDENTIFIED BY 'userpass' WITH GRANT OPTION;

 

Note the 'remotehost' section.

Link to comment
Share on other sites

#### SAMPLE CODE ####

<?php

 

$dbServer = '192.168.1.30';

$dbUser= 'george';

$dbPass= 'password';

 

 

if(!($link = mysql_connect($dbServer, $dbUser, $dbPass)))

        echo mysql_error($link);

else

        print "Connected successfully<br>";

 

mysql_close($link);

?>

#################

 

#### COMMAND-LINE RESULTS ####

# php ./connection.php

Connected successfully<br>

 

##########################

 

###Web Results with mysql_error statement ###

 

Warning: mysql_connect() [function.mysql-connect]: Can't connect to MySQL server on '192.168.1.30' (13) in /var/www/httpdocs/connection.php on line 9

 

#########################

 

This is all from Server A (mysql_php_client_host) TO Server B (mysql_server_host)

 

Link to comment
Share on other sites

Maybe your 'hostname' differs from that which you granted to mysql.

 

I would try....

 

GRANT ALL PRIVILEGES ON dbname TO 'username'@'*' IDENTIFIED BY 'userpass' WITH GRANT OPTION;

 

For testing purposes.

Link to comment
Share on other sites

create user 'username'@'*' identified by 'pass1';

 

This doesn't work. I still have the same connection problem from the web and no connection problem running the script remotely for the command-line: php ./connect.php

 

-Phibertek

Link to comment
Share on other sites

Well Im not really sure how, but maybe the mysql extension has been disabled from using remote connections when called from within a web server context.

 

We would need to see all the relevent php.ini entries.

Link to comment
Share on other sites

engine = On

zend.ze1_compatibility_mode = Off

short_open_tag = On

asp_tags = Off

precision    =  14

y2k_compliance = On

output_buffering = 4096

zlib.output_compression = Off

implicit_flush = Off

unserialize_callback_func=

serialize_precision = 100

allow_call_time_pass_reference = Off

safe_mode = Off

safe_mode_gid = Off

safe_mode_include_dir =

safe_mode_exec_dir =

safe_mode_allowed_env_vars = PHP_

safe_mode_protected_env_vars = LD_LIBRARY_PATH

disable_functions =

disable_classes =

 

expose_php = On

max_execution_time = 30    ; Maximum execution time of each script, in seconds

max_input_time = 60    ; Maximum amount of time each script may spend parsing request data

memory_limit = 16M      ; Maximum amount of memory a script may consume

error_reporting  =  E_ALL

display_errors = Off

display_startup_errors = Off

log_errors = On

log_errors_max_len = 1024

ignore_repeated_errors = Off

ignore_repeated_source = Off

report_memleaks = On

track_errors = Off

variables_order = "EGPCS"

register_globals = Off

register_long_arrays = Off

register_argc_argv = Off

auto_globals_jit = On

post_max_size = 8M

magic_quotes_gpc = Off

magic_quotes_runtime = Off

magic_quotes_sybase = Off

auto_prepend_file =

auto_append_file =

default_mimetype = "text/html"

doc_root =

user_dir =

extension_dir = "/usr/lib64/php/modules"

enable_dl = On

file_uploads = On

upload_max_filesize = 2M

allow_url_fopen = On

default_socket_timeout = 60

 

 

[Date]

 

[syslog]

define_syslog_variables  = Off

 

 

 

[sql]

sql.safe_mode = Off

 

[ODBC]

odbc.allow_persistent = On

odbc.check_persistent = On

odbc.max_persistent = -1

odbc.max_links = -1

odbc.defaultlrl = 4096

odbc.defaultbinmode = 1

 

[MySQL]

mysql.allow_persistent = On

mysql.max_persistent = -1

mysql.max_links = -1

mysql.default_port =

mysql.default_socket =

mysql.default_host =

mysql.default_user =

mysql.default_password =

mysql.connect_timeout = 60

mysql.trace_mode = Off

 

[MySQLi]

 

mysqli.max_links = -1

mysqli.default_port = 3306

mysqli.default_socket =

mysqli.default_host =

mysqli.default_user =

mysqli.default_pw =

mysqli.reconnect = Off

 

[mSQL]

msql.allow_persistent = On

msql.max_persistent = -1

msql.max_links = -1

 

 

[session]

session.save_handler = files

session.save_path = "/var/lib/php/session"

session.use_cookies = 1

session.name = PHPSESSID

session.auto_start = 0

session.cookie_lifetime = 0

session.cookie_path = /

session.cookie_domain =

session.serialize_handler = php

session.gc_probability = 1

session.gc_divisor    = 1000

session.gc_maxlifetime = 1440

session.bug_compat_42 = 0

session.bug_compat_warn = 1

session.referer_check =

session.entropy_length = 0

session.entropy_file =

session.cache_limiter = nocache

session.cache_expire = 180

session.use_trans_sid = 0

session.hash_function = 0

session.hash_bits_per_character = 5

url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=fakeentry"

 

[MSSQL]

mssql.allow_persistent = On

mssql.max_persistent = -1

mssql.max_links = -1

mssql.min_error_severity = 10

mssql.min_message_severity = 10

mssql.compatability_mode = Off

mssql.secure_connection = Off

 

[Assertion]

 

 

[Verisign Payflow Pro]

pfpro.defaulthost = "test-payflow.verisign.com"

pfpro.defaultport = 443

pfpro.defaulttimeout = 30

 

[COM]

 

[mbstring]

 

[FrontBase]

 

[gd]

 

[exif]

 

[Tidy]

tidy.clean_output = Off

 

[soap]

soap.wsdl_cache_enabled=1

soap.wsdl_cache_dir="/tmp"

soap.wsdl_cache_ttl=86400

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.