return [
'dsn' => 'mysql:host=localhost;dbname=test;charset=utf8',
'user' => 'root',
'password' => '',
];
<?php
namespace wfm;
require_once 'vendor/autoload.php';
use RedBeanPHP\R;
class Db
{
use TSingleton;
private function __construct()
{
if (!defined('CONFIG')) {
define('CONFIG', __DIR__ . '/config');
}
if (!defined('DEBUG')) {
define('DEBUG', false);
}
$db = require CONFIG . '/config_db.php';
R::setup($db['dsn'], $db['user'], $db['password']);
if (!R::testConnection()) {
throw new \Exception('No connection to DB', 503);
}
R::freeze(true);
if (DEBUG) {
R::debug(true, 3);
}
}
}
var pool = mysql.createPool({
host: "хост",
user: "пользователь",
password: "пароль",
database: "датабаза",
port: 3306,
});
pool.getConnection(function (err, connection) {
if (err) {
console.log("Ошибка датабазы: " + err);
throw err;
}
else {
console.log("Датабаза подключена");
connection.query('SELECT * FROM `fac`', function (err, result) {
if (err) {
console.log("Ошибка выполнения запроса: " + err);
throw err;
}
else {
console.log(result);
// do something with the result
}
connection.release(); // always release the connection after you're done with it
});
}
});
if ( isset ( $_POST['id'] ) )
{
$ids = implode( ',', $_POST['id'] );
$query = ("
INSERT INTO
`order_archive` (`id`, `user_id`, `articul_id`, `barcode`, `quantity`)
SELECT
`id`, `user_id`, `articul_id`, barcode`, `quantity`
FROM
`order`
WHERE
`id` IN ($ids);
DELETE FROM `order` WHERE `id` IN ($ids)");
if(mysqli_multi_query($db, $query)) {
echo 'Customer removed: ' .$ids;
} else {
echo "Error querying database: " . mysqli_error($db);
}
}