0

I have problem connecting SQL with php. I don't even get an SQL error, just an ugly PHP error message:

"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}( )
..\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.

I read something about the mysql_ functions being old and unsupported, maybe that's my problem? 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!!!";

    }
}           
?>
4
  • 1
    What's line 19, also try using PDO instead of mysql_connect Commented Sep 6, 2014 at 16:46
  • line 19 is $link = mysql_connect($hostname, $sqluser, $sqlpass) or die("error zzzzz"); if PDO is some extantion that need to be install on the server its not possable .. Commented Sep 6, 2014 at 16:49
  • 2
    Try echo mysql_error() after that line and see if it says anything useful. It's probably not the cause of the problem but you shouldn't be using mysql_ functions anymore (they are no longer supported), you should be using mysqli_ functions or PDO instead. Commented Sep 6, 2014 at 16:54
  • 1
    @OrHalimi Most PHP installations comes with PDO/MySQLi by default AFAIK, worst case you will only have to remove config comment lines on the php.ini file but rarely needed. Commented Sep 6, 2014 at 16:56

2 Answers 2

1
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? :) Also i recommend you to use MySQLi or PDO as from the version 5.4 the mysql_* functions are considered deprecated.

Sign up to request clarification or add additional context in comments.

1 Comment

amm...that how i saw poeple do it? i will try with mysqli, thanks :-)
0

Hey guys thanks for help, but it seem the problem was a security config of the remote server.

I will look on mysqli trough.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.