简体   繁体   English

无法使用PHP访问远程MYSQL数据库

[英]Can't access remote MYSQL database using PHP

I have problem connecting SQL with php. 我在将SQL与php连接时遇到问题。 I don't even get an SQL error, just an ugly PHP error message: 我什至没有收到SQL错误,只有一条难看的PHP错误消息:

"Warning: mysql_connect(): in C:\\wamp\\www\\guildcreator\\include\\sql_conn.php on line 19 Call Stack Time Memory Function Location 1 0.0004 252040 {main}( ) “警告:mysql_connect():在C:\\ wamp \\ www \\ guildcreator \\ include \\ sql_conn.php中的第19行调用堆栈时间存储函数位置1 0.0004 252040 {main}()
..\\sub.php:0 2 0.0009 255208 include( 'C:\\wamp\\www\\guildcreator\\include\\sql_conn.php' ) ..\\sub.php:5 3 0.0009 256344 mysql_connect ( )" .. \\ sub.php:0 2 0.0009 255208 include('C:\\ wamp \\ www \\ guildcreator \\ include \\ sql_conn.php').. \\ sub.php:5 3 0.0009 256344 mysql_connect()“

At first I thought that I wasn't creating a connection to the server. 起初我以为我没有在建立与服务器的连接。 I tried various different combinations of the same address, with and without the port number. 我尝试过使用和不使用端口号的同一地址的各种不同组合。 I don't understand why I am getting this error, because if mysql_connect fails I should be seeing the die() message. 我不明白为什么会收到此错误,因为如果mysql_connect失败,我应该会看到die()消息。

I read something about the mysql_ functions being old and unsupported, maybe that's my problem? 我读到一些有关mysql_函数过旧且不受支持的信息,也许这是我的问题吗? Any help would be great :-) 任何帮助将是巨大的:-)

Here's the code that I am using: 这是我正在使用的代码:

$hostname = 'lolisrael.co.il:3306';
$sqluser = 'XXXXXX';
$sqlpass = 'XXXXXXXXX';

$link = mysql_connect($hostname, $sqluser, $sqlpass) or die("error zzzzz"); 
if ($link)
    $db = mysql_select_db('_db', $link) or die("no db found");

the submite page for reference: 提交页面供参考:

<?php 
if(isset($_POST['free_text'])) 
{
    echo "<p>".$_POST['free_text']."</p>";
    include "include/sql_conn.php";
    if(isset($db))
    {
        $free_text = mysql_real_escape_string($_POST['free_text']);
        $sql = "INSERT
            INTO
            orhalimi_test_conn(free_text)
            VALUES ('{$free_text}')";
        if(mysql_query($sql))
            echo "ITS WORK!!!";

    }
}           
?>
if ($link)
    $db = mysql_select_db('_db', $link) or die("no db found");

why would you use the mysql_select_db() function into a variable? 为什么将mysql_select_db()函数用作变量? :) Also i recommend you to use MySQLi or PDO as from the version 5.4 the mysql_* functions are considered deprecated. :)另外,我建议您使用MySQLi或PDO,因为从5.4版开始,不再考虑使用mysql_ *函数。

Hey guys thanks for help, but it seem the problem was a security config of the remote server. 大家好,感谢您的帮助,但问题似乎出在远程服务器的安全配置上。

I will look on mysqli trough. 我将研究mysqli槽。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM