首页 > 解决方案 > Alternative connection to database without PHP?

问题描述

Objective: Update prices of products between databases: Shop's server DB has the latest prices and website's DB need to be updated accordingly with any "each 24 hours" script (I'll look this up later).

I'm using Ionos as hosting for the website, and The server is shared, so I can't touch php.ini or add files for php.

I'm trying to connect to a SQL server DB, but since it requires dll libraries to be installed and to modify the php.ini, I can't do that.

I can't either make it from the other side, If I make it from an external server in order to update the prices of the website, they don't allow to make connections out of the context of the server.

So, I know that the solution is to upgrade the hosting's plan and pay more and so on, so I have a virtual server for my own. But before doing that, is there any other way to establish this connection without using php? Is there something else that allows me to create a DB connection?

The fatal errors appears as soon as sqlsrv_connect is read as there is no library to load this function.

$serverName = "x, 0000"; 
$connectionInfo = array( "Database"=>"x", "UID"=>"x", "PWD"=>"xxx");
$conn = sqlsrv_connect( $serverName, $connectionInfo);

Edit: Comes to my mind... Maybe a solution would be to tell this php file to load php.ini and so on from another server if that's possible?

标签: phpsql-serverdatabase

解决方案


您可以在数据库服务器上调用 JSON 端点(尽管保护端点(超出我的回答范围))https://3v4l.org/Gpi28

<?php

// MSSQL server side

$data = [
    1 => 'hello',
    2 => 'world',
];

// Imagine $data above is the array of rows returned by the db query

header('Content-Type: application/json');
echo json_encode($data);
exit;


// IONOS Side
$json = file_get_contents('http://your-database-server/some/url/or/other');
$data = json_decode(true);
// Now do your updates

// NB This is an INSECURE example, people who know the URL can see this data!

推荐阅读