Koozali.org: home of the SME Server
Contribs.org Forums => Koozali SME Server 10.x => Topic started by: rrizley on April 13, 2022, 11:57:12 PM
-
So after thoroughly searching Google and this forum I have not found a resolution. I am attempting to connect to my MySQL/MariaDB with PHP on my freshly installed SME Server 10 I get a connection refused. This I have tried
config setprop mysqld LocalNetworkingOnly no
expand-template /etc/my.cnf
sv t /service/mysqld
but the sv command returns 'unable to change to service directory; file does not exist'
I see on one post that LocalNetworkingOnly no is strongly discouraged I will change that to yes if I get my connection
working. At this point I am not too concerned about security I am using SME 10 primarily for my own purposes
this I have tried
$mysqliconn = new mysqli("<my host ip address>", "<my user>", "<my user password","<mydatabase>");
and this
$mysqliconn = mysqli_connect("<my host ip address>", "<my user>", "<my user password","<mydatabase>");
I am running my PHP script using putty from the command line: php <my php script>
php version 5.4.16
-
be carreful that while php cli default is 5.4, in your ibays via webserver it is 7.4.
that said you are using an Unix/ Linux server so you are expected to user socket connection.
$host="localhost";
$socket="/var/lib/mysql/mysql.sock";
$port="";
$mysqli = new mysqli($host, $user, $password, $dbname, $port, $socket);
-
$host="localhost:/var/lib/mysql/mysql.sock";
should also work
-
Thank you. I am now getting a Connected successfully but I am having difficulty with my query. If there is a manual I could review that would be helpful. I have not found a suitable PHP manual for my version nor a MySQL manual
This is what I have tried
$QueryString = "SELECT * FROM faxstorage.faxstorage";
echo "Begin query...\n";
$QueryResult = $mysqli->query('SELECT * FROM faxstorage.faxstorage');
echo "End query... $QueryResult\n";
foreach ($QueryResult->fetch_assoc() as $row)
echo " id = " . $row['filename'] . "\n";
perhaps not good practice to name my DATABASE name same as my TABLE name but it has worked in the past
-
you are using mariadb 5.5
and php 7.4 if running in a web browser.
if you are testing with cli, the. you need to use the command php74 in place of php.
php74 myscript.php
-
got it to work with this and thought that someone else might find the code useful
$filename = "'" . "zzzfilename234" . "'";
$QueryString = "SELECT * FROM faxstorage WHERE filename = " . $filename;
$QueryResult = $mysqli->query($QueryString);
foreach($QueryResult AS $rowarray)
foreach($rowarray AS $rowval)
echo '~' . $rowval . "~\n";