{"id":16560668,"url":"https://github.com/mathieu2301/php-mysql-bridge","last_synced_at":"2026-04-12T14:46:23.979Z","repository":{"id":92266893,"uuid":"298093871","full_name":"Mathieu2301/PHP-MySQL-Bridge","owner":"Mathieu2301","description":"PHP MySQL SocketIO Bridge","archived":false,"fork":false,"pushed_at":"2021-12-31T00:20:28.000Z","size":663,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-15T13:30:12.889Z","etag":null,"topics":["bridge","database","mysql","mysql-database","nodejs","php-mysql-bridge","php-server","socket"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Mathieu2301.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-09-23T21:03:55.000Z","updated_at":"2021-12-31T00:20:31.000Z","dependencies_parsed_at":"2023-06-19T04:52:52.981Z","dependency_job_id":null,"html_url":"https://github.com/Mathieu2301/PHP-MySQL-Bridge","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mathieu2301%2FPHP-MySQL-Bridge","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mathieu2301%2FPHP-MySQL-Bridge/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mathieu2301%2FPHP-MySQL-Bridge/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mathieu2301%2FPHP-MySQL-Bridge/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Mathieu2301","download_url":"https://codeload.github.com/Mathieu2301/PHP-MySQL-Bridge/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241956510,"owners_count":20048643,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bridge","database","mysql","mysql-database","nodejs","php-mysql-bridge","php-server","socket"],"created_at":"2024-10-11T20:29:43.055Z","updated_at":"2025-12-31T01:02:52.180Z","avatar_url":"https://github.com/Mathieu2301.png","language":"PHP","readme":"# PHP-MySQL-SocketIO-Bridge\nPHP MySQL SocketIO Bridge\n\nYou can use this library to connect to your local PHP-MySQL database from a NodeJS process.\n\n## Installation\n\n```\nnpm install https://github.com/Mathieu2301/PHP-MySQL-SocketIO-Bridge.git\n```\n\n## PHP Installation\n  Serve the ``/bridge`` folder on your PHP server.\n \n  Create a ``/mysql.php`` file\n  ```php\n  \u003c?\n    if (!password_verify('PASS_HASH', $_SERVER['QUERY_STRING'])) exit();\n    $pdo = new PDO('mysql:host=127.0.0.1;dbname=database;charset=utf8mb4', 'root', 'pass', [\n      PDO::ATTR_EMULATE_PREPARES   =\u003e false,\n      PDO::ATTR_ERRMODE            =\u003e PDO::ERRMODE_EXCEPTION,\n      PDO::ATTR_DEFAULT_FETCH_MODE =\u003e PDO::FETCH_ASSOC,\n      PDO::MYSQL_ATTR_INIT_COMMAND =\u003e 'SET NAMES utf8mb4'\n    ]);\n    $ip = 'http://my-node-js-host.com/path/to/index.php';\n  ?\u003e\n  ```\n\n## NodeJS Initialization\n\n Start by importing the library\n\n```javascript\nconst PMSB = require('pmsb');\n```\n\n### Connect to the bridge (your PHP server)\n```javascript\nconst mysql = PMSB('my-php-host.com', 'PASS');\n```\n\n### Send MySQL request\n```javascript\n(async () =\u003e {\n  // Fetch example\n  await mysql.query('UPDATE my_table SET name = ? WHERE id = ?', [ 'test', 2 ]).exec();\n\n  // Fetch example (Returns only the first element)\n  const fetchRq = await mysql.query('SELECT * FROM my_table').fetch();\n  console.log(fetchRq.data);\n\n  // FetchAll example (Returns a list of all elements)\n  const fetchAllRq = await mysql.query('SELECT * FROM my_table').fetchAll();\n  console.log(fetchAllRq.data);\n})();\n```\n\n## Tips\n\nYou can use fetchmodes\n```javascript\n// Availables are :\nmysql.FETCH.ASSOC;\nmysql.FETCH.COLUMN;\nmysql.FETCH.UNIQUE;\n\n// FETCH_UNIQUE example :\nconst ex1 = await mysql.query('SELECT ID, name, email FROM users').fetchAll(mysql.FETCH.UNIQUE);\nconsole.log(ex1.data); // Template: { '{ID}': { name: '...', email: '...' }, '{ID_2}': { name: '...', email: '...' }, ... }\n\n// Combination example :\nconst ex2 = await mysql.query('SELECT ID, name FROM my_table').fetchAll(mysql.FETCH.COLUMN | mysql.FETCH.UNIQUE);\nconsole.log(ex2.data); // Template: { '{ID}': '{name}', '{ID_2}': '{name_2}', ... }\n```\n\nYou can use promise ``.then()``\n```javascript\nmysql.query('SELECT * FROM my_table').fetch().then((rs) =\u003e {\n  console.log(rs.data);\n});\n```\n\nLatency measure\n```javascript\nconst startTime = Date.now();\nconst data = await sql.query('SELECT * FROM my_table').fetchAll();\n\nconsole.log(Date.now() - startTime, 'ms', data);\n```\n\nUse custom port\n```javascript\nconst mysql = PMSB('my-php-host.com', 'PASS', 8000);\n```\n\nUse SSL Sockets\n```javascript\nconst fs = require('fs');\nconst mysql = PMSB('my-php-host.com', 'PASS', 443, {\n  cert: fs.readFileSync('./certif.crt'),\n  key: fs.readFileSync('./private.key'),\n});\n```\n\n___\n## Problems\n\n If you have errors in console or unwanted behavior please create an issue [here](https://github.com/Mathieu2301/PHP-MySQL-SocketIO-Bridge/issues).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmathieu2301%2Fphp-mysql-bridge","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmathieu2301%2Fphp-mysql-bridge","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmathieu2301%2Fphp-mysql-bridge/lists"}