Can't get php script to connect to asterisk internal mysql database

0

I'm trying to get a PHP script to connect to Asterisks internal sql database.

I tried the to use the standard method for example

$con = mysqli_connect("192.168.1.126","root","mysql","asterisk");

However when I log into the asterisk server to access the mysql database all I need it to type "mysql" and I'm logged in.

Im wondering is it possible for my php script to connect to asterisk internal database.

//edit The following mysql error is shown

Warning: mysqli_connect(): (HY000/2003): Can't connect to MySQL server on '192.168.1.126' (111) in /var/www/html/project/sipSubScript.php on line 6
Failed to connect to MySQL: Can't connect to MySQL server on '192.168.1.126' (111)

Bilbo

Posted 2014-08-24T02:20:51.400

Reputation: 21

Can you do it from CLI? https://sites.google.com/site/bantisandy/home/asterisk/asmysql-database

– krowe – 2014-08-24T02:37:56.123

@Bilbo: Did you checked connection to MySQL server from any MySQL client software apart from connecting to it through code? – Renju Chandran chingath – 2014-08-24T03:59:44.837

Ya I tried connecting through the command line. I also tried telnet. I can connect locally using the command line, but when i try from another machine it wont work. My other machine is also on the local network. Thanks for the replies guys – Bilbo – 2014-08-24T04:30:34.453

Answers

0

The problem in the end was that mysql was only listening for connections from localhost. So to solve the problem find your my.cnf file which should be located in the /etc/ folder.

To find it I used ls -l my* im not sure if this commad is correct but it found it for me anyway.

Inside the file should look like this:

[mysqld]
#bind-address = 127.0.0.1   //uncommented this line using #
general_log = 1
general_log_file = /var/log/mysql/mysql.log
datadir=/var/lib/mysql/mysql/sock
user=root
symbolic-links=0

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

Next you need to restart mysql and you done, this can be done using:

sudo /etc/init.d/mysqld restart

Bilbo

Posted 2014-08-24T02:20:51.400

Reputation: 21