Reputation: 671
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!!!";
}
}
?>
Upvotes: 0
Views: 86
Reputation: 671
Hey guys thanks for help, but it seem the problem was a security config of the remote server.
I will look on mysqli trough.
Upvotes: 0
Reputation:
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.
Upvotes: 1