php - 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?
解决方案
您可以在数据库服务器上调用 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!
推荐阅读
- bash - 如何比较 3 个或更多文件的修改日期
- r - 如何在 R Shiny 中的“navbarPage”菜单项之间同步“selectizeInput”?
- javascript - 如何让 for 循环中的代码在第一次迭代之后的每次迭代之间等待?
- bash - AWK 中的 Substr 在 Ubuntu 中返回空行
- java - 如何让tomcat主线程获得更多客户的请求而不是为future.isDone()休眠
- python - numpy数组的布尔/非零索引循环的替代方法
- html - 我无法使用 td colspan 和 rowspan 创建此表
- c# - 如何将泛型类型传递给泛型方法?
- javascript - 试图只使用高阶函数来制作中继器功能?
- c++ - 使用 constexpr 和 std::array 静态初始化获取闰年以替换动态初始化的 std::vector