Не работает MySQL с связкой PHP + Lua

cheremuxa

Известный
Автор темы
430
200
Версия MoonLoader
.026-beta
Хай, решил сделать так:
Lua -> PHP -> MySQL
НЕ ВЕСЬ КОД!!!!!!!
Lua (ТОЛЬКО ТО, ЧТО ДЕЛАЛ ДЛЯ ЗАПРОСА POST) :
Lua:
local copas = require 'copas'
local http = require 'copas.http'

==========================================================================

function httpRequest(request, body, handler) -- copas.http
    -- start polling task
    if not copas.running then
        copas.running = true
        lua_thread.create(function()
            wait(0)
            while not copas.finished() do
                local ok, err = copas.step(0)
                if ok == nil then error(err) end
                wait(0)
            end
            copas.running = false
        end)
    end
    -- do request
    if handler then
        return copas.addthread(function(r, b, h)
            copas.setErrorHandler(function(err) h(nil, err) end)
            h(http.request(r, b))
        end, request, body, handler)
    else
        local results
        local thread = copas.addthread(function(r, b)
            copas.setErrorHandler(function(err) results = {nil, err} end)
            results = table.pack(http.request(r, b))
        end, request, body)
        while coroutine.status(thread) ~= 'dead' do wait(0) end
        return table.unpack(results)
    end
end

==========================================================================

                local curS, nickn = currentServer, playerNick
                local data = 'curS=' .. curS .. '&nickname=' .. nickn
                httpRequest('https://***.xyz/vk_notify.php/', data)

PHP:

PHP:
<?php

$mysql = mysqli_connect('127.0.0.1', '****', '****', '****');
if (!$mysql) exit('[CONNECTION ERROR]');

if ($stmt = $mysql->prepare('INSERT INTO `test` (`nickn`, `curS`) VALUES (?, ?)')) {
    $curS = (isset($_POST['curS']) ? strval($_POST['curS']) : '');
    $nickn = (isset($_POST['nickn']) ? strval($_POST['nickn']) : '');
    $stmt->bind_param('ss', $login, $pass);
    if ($stmt->execute()) {
        echo '+';
        $stmt->close();
    } else {
        echo '-';
        $stmt->close();
    }
}
?>

**** - скрыл данные

MySQL - ничего нету, не добавлял

В MySQL ничего не появляется, никакой базы , ничего
Поменял $login, $pass на $curS и $nickn - результат нулевый
Хай, решил сделать так:
Lua -> PHP -> MySQL
НЕ ВЕСЬ КОД!!!!!!!
Lua (ТОЛЬКО ТО, ЧТО ДЕЛАЛ ДЛЯ ЗАПРОСА POST) :
Lua:
local copas = require 'copas'
local http = require 'copas.http'

==========================================================================

function httpRequest(request, body, handler) -- copas.http
    -- start polling task
    if not copas.running then
        copas.running = true
        lua_thread.create(function()
            wait(0)
            while not copas.finished() do
                local ok, err = copas.step(0)
                if ok == nil then error(err) end
                wait(0)
            end
            copas.running = false
        end)
    end
    -- do request
    if handler then
        return copas.addthread(function(r, b, h)
            copas.setErrorHandler(function(err) h(nil, err) end)
            h(http.request(r, b))
        end, request, body, handler)
    else
        local results
        local thread = copas.addthread(function(r, b)
            copas.setErrorHandler(function(err) results = {nil, err} end)
            results = table.pack(http.request(r, b))
        end, request, body)
        while coroutine.status(thread) ~= 'dead' do wait(0) end
        return table.unpack(results)
    end
end

==========================================================================

                local curS, nickn = currentServer, playerNick
                local data = 'curS=' .. curS .. '&nickname=' .. nickn
                httpRequest('https://***.xyz/vk_notify.php/', data)

PHP:

PHP:
<?php

$mysql = mysqli_connect('127.0.0.1', '****', '****', '****');
if (!$mysql) exit('[CONNECTION ERROR]');

if ($stmt = $mysql->prepare('INSERT INTO `test` (`nickn`, `curS`) VALUES (?, ?)')) {
    $curS = (isset($_POST['curS']) ? strval($_POST['curS']) : '');
    $nickn = (isset($_POST['nickn']) ? strval($_POST['nickn']) : '');
    $stmt->bind_param('ss', $login, $pass);
    if ($stmt->execute()) {
        echo '+';
        $stmt->close();
    } else {
        echo '-';
        $stmt->close();
    }
}
?>

**** - скрыл данные

MySQL - ничего нету, не добавлял

В MySQL ничего не появляется, никакой базы , ничего
Поменял $login, $pass на $curS и $nickn - результат нулевый
up
 
Последнее редактирование:

Pakulichev

Software Developer & System Administrator
Друг
1,789
2,133
Сначала нужно создать базу в MySQL, в ней нужно создать таблицу test с полями nickn и curS.
Потом в 9 строке PHP исправить переменные на нужные, потому что там $login и $pass.
Только после этого всё должно работать.
 

cheremuxa

Известный
Автор темы
430
200
Сначала нужно создать базу в MySQL, в ней нужно создать таблицу test с полями nickn и curS.
Потом в 9 строке PHP исправить переменные на нужные, потому что там $login и $pass.
Только после этого всё должно работать.
уже так сделал - ничего
 

cheremuxa

Известный
Автор темы
430
200
Lua:
local response, code, headers, status = httpRequest(...)
print(response)
понял, дома посмотрю
Lua:
local response, code, headers, status = httpRequest(...)
print(response)
сделал как ты и сказал
LUA:
Lua:
local copas = require 'copas'
local http = require 'copas.http'




function httpRequest(request, body, handler) -- copas.http
    -- start polling task
    if not copas.running then
        copas.running = true
        lua_thread.create(function()
            wait(0)
            while not copas.finished() do
                local ok, err = copas.step(0)
                if ok == nil then error(err) end
                wait(0)
            end
            copas.running = false
        end)
    end
    -- do request
    if handler then
        return copas.addthread(function(r, b, h)
            copas.setErrorHandler(function(err) h(nil, err) end)
            h(http.request(r, b))
        end, request, body, handler)
    else
        local results
        local thread = copas.addthread(function(r, b)
            copas.setErrorHandler(function(err) results = {nil, err} end)
            results = table.pack(http.request(r, b))
        end, request, body)
        while coroutine.status(thread) ~= 'dead' do wait(0) end
        return table.unpack(results)
    end

        local nickn = sampGetPlayerNickname(playerPed)
        local data = 'nickname=' .. nickn
        httpRequest('https://***.xyz/vk_notify.php/', data)
        local response, code, headers, status = httpRequest('https://***.xyz/vk_notify.php/', data)
        print(response)

end


убрал curS и оставил nickN
PHP:
PHP:
<?php
$mysql = mysqli_connect('127.0.0.1', '***', '***', '***');

if (!$mysql) exit('[CONNECTION ERROR]');

if ($stmt = $mysql->prepare('INSERT INTO `test` (`nickn`) VALUES (?, ?)')) {
    $nickn = (isset($_POST['nickn']) ? strval($_POST['nickn']) : '');
    $stmt->bind_param('ss', $curS, $nickn);
    if ($stmt->execute()) {
        echo '+';
        $stmt->close();
    } else {
        echo '-';
        $stmt->close();
    }
}
?>

проблема:
не вывело ничего с помощью:
Lua:
        local response, code, headers, status = httpRequest('https://***.xyz/vk_notify.php/', data)
        print(response)
 
Последнее редактирование:

Pakulichev

Software Developer & System Administrator
Друг
1,789
2,133
понял, дома посмотрю

сделал как ты и сказал
LUA:
Lua:
local copas = require 'copas'
local http = require 'copas.http'




function httpRequest(request, body, handler) -- copas.http
    -- start polling task
    if not copas.running then
        copas.running = true
        lua_thread.create(function()
            wait(0)
            while not copas.finished() do
                local ok, err = copas.step(0)
                if ok == nil then error(err) end
                wait(0)
            end
            copas.running = false
        end)
    end
    -- do request
    if handler then
        return copas.addthread(function(r, b, h)
            copas.setErrorHandler(function(err) h(nil, err) end)
            h(http.request(r, b))
        end, request, body, handler)
    else
        local results
        local thread = copas.addthread(function(r, b)
            copas.setErrorHandler(function(err) results = {nil, err} end)
            results = table.pack(http.request(r, b))
        end, request, body)
        while coroutine.status(thread) ~= 'dead' do wait(0) end
        return table.unpack(results)
    end

        local nickn = sampGetPlayerNickname(playerPed)
        local data = 'nickname=' .. nickn
        httpRequest('https://***.xyz/vk_notify.php/', data)
        local response, code, headers, status = httpRequest('https://***.xyz/vk_notify.php/', data)
        print(response)

end


убрал curS и оставил nickN
PHP:
PHP:
<?php
$mysql = mysqli_connect('127.0.0.1', '***', '***', '***');

if (!$mysql) exit('[CONNECTION ERROR]');

if ($stmt = $mysql->prepare('INSERT INTO `test` (`nickn`) VALUES (?, ?)')) {
    $nickn = (isset($_POST['nickn']) ? strval($_POST['nickn']) : '');
    $stmt->bind_param('ss', $curS, $nickn);
    if ($stmt->execute()) {
        echo '+';
        $stmt->close();
    } else {
        echo '-';
        $stmt->close();
    }
}
?>

проблема:
не вывело ничего с помощью:
Lua:
        local response, code, headers, status = httpRequest('https://***.xyz/vk_notify.php/', data)
        print(response)
Что выводит переменная code?
 

cheremuxa

Известный
Автор темы
430
200
RESPONSE [ML] (script) 1.lua: nil
CODE [ML] (script) 1.lua: D:\GTAFORFILM\moonloader\lib\copas.lua:40: D:\GTAFORFILM\moonloader\lib\copas.lua:40: D:\GTAFORFILM\moonloader\lib\copas.lua:387: loop or previous error loading module 'ssl'
HEADERS [ML] (script) 1.lua: nil
STATUS [ML] (script) 1.lua: nil
убрал HTTPS протокол и теперь вышло это:

RESPONSE [ML] (script) ***.lua:
CODE [ML] (script) ***.lua: 200
HEADERS [ML] (script) ***.lua: table: 0x0f29c418
STATUS [ML] (script) ***.lua: HTTP/1.1 200 OK

но в базе ничего не создало
RESPONSE [ML] (script) 1.lua: nil
CODE [ML] (script) 1.lua: D:\GTAFORFILM\moonloader\lib\copas.lua:40: D:\GTAFORFILM\moonloader\lib\copas.lua:40: D:\GTAFORFILM\moonloader\lib\copas.lua:387: loop or previous error loading module 'ssl'
HEADERS [ML] (script) 1.lua: nil
STATUS [ML] (script) 1.lua: nil

убрал HTTPS протокол и теперь вышло это:

RESPONSE [ML] (script) ***.lua:
CODE [ML] (script) ***.lua: 200
HEADERS [ML] (script) ***.lua: table: 0x0f29c418
STATUS [ML] (script) ***.lua: HTTP/1.1 200 OK

но в базе ничего не создало

что-то додумался сделать, но у меня вместо текста как это должно быть просто 0 и 0
 
Последнее редактирование: