Error making a record in the bd mysql on a host

0

How about, I have a form, I've uploaded it to a host, for example www.example.com/register and at the time of registering I get the following

Warning: mysql_connect(): Connection refused in /home/xxx/xx.xx/prueba/controllerdb.php on line 16

Warning: mysql_query(): No such file or directory in /home/xxx/xx.xx/prueba/controllerdb.php on line 34

Warning: mysql_query(): A link to the server could not be established in /home/xxx/xx.xx/prueba/controllerdb.php on line 34

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /home/xxx/xx.xx/prueba/controllerdb.php on line 35

Warning: mysql_query(): No such file or directory in //home/xxx/xx.xx/prueba/controllerdb.php on line 49

Warning: mysql_query(): A link to the server could not be established in //home/xxx/xx.xx/prueba/controllerdb.php on line 49
Invalid query: No such file or directory

This is controllerdb.php

    <?php
class DBController {
private $host = "www.xxx.mx";
private $user = "xxxx";
private $password = "xxxxx";
private $database = "xxxx";

function __construct() {
    $conn = $this->connectDB();
    if(!empty($conn)) {
        $this->selectDB($conn);
    }
}

function connectDB() {
    $conn = mysql_connect($this->host,$this->user,$this->password);
    return $conn;
}

function selectDB($conn) {
    mysql_select_db($this->database,$conn);
}

function runQuery($query) {
    $result = mysql_query($query);
    while($row=mysql_fetch_assoc($result)) {
        $resultset[] = $row;
    }
    if(!empty($resultset))
        return $resultset;
}

function numRows($query) {
    $result  = mysql_query($query);
    $rowcount = mysql_num_rows($result);
    return $rowcount;
}

function updateQuery($query) {
    $result = mysql_query($query);
    if (!$result) {
        die('Invalid query: ' . mysql_error());
    } else {
        return $result;
    }
}

function insertQuery($query) {
    $result = mysql_query($query);
    if (!$result) {
        die('Invalid query: ' . mysql_error());
    } else {
        return $result;
    }
}

function deleteQuery($query) {
    $result = mysql_query($query);
    if (!$result) {
        die('Invalid query: ' . mysql_error());
    } else {
        return $result;
    }
}
}

    ?>

It should be clear that I have the bd created in PHPMyAdmin of the host.

Locally it works very well for me.

Thanks for the help.

    
asked by x4mp73r 08.04.2016 в 22:22
source

2 answers

0

I solved this in the following way: To the function connectDB I added the database:

function connectDB() {
    $conn = mysql_connect($this->host,$this->user,$this->password,$this->database);
    return $conn;
}

Also to the function to use the bd, selectDB, I removed the variable conn :

function selectDB($conn) {
    mysql_select_db($this->database);
}
    
answered by 09.04.2016 / 04:29
source
0

If it works well locally, but if the connection is made from another machine and it fails you, surely the machine with the database does not have the port open to be able to connect from outside.

Check if the database connection port is open and accessible to other machines.

    
answered by 09.04.2016 в 02:32