Skip to content

bragful/ephp_mysql

Repository files navigation

ePHP MySQL

Copyright (c) 2017-2019 Altenwald Solutions, S.L.

Authors: "Manuel Rubio" ([email protected]).

Build Status Codecov License: LGPL 2.1

This library implements the MySQL client library functions as is in PHP code for ephp keeping in mind to have it as pure 100% Erlang.

ePHP MySQL requires to be run over an Erlang/OTP 18+, but not all the versions are full compatible or recommended. See the list:

Erlang Version Support Notes
22.0 ✔️ Recommended if you use OTP 22
21.3  :heavy_check_mark: Recommended if you use OTP 21
21.2 ✔️
21.1 ✔️
21.0 ✔️
20.3 fail SSL and number conversion.
20.2 ✔️ Recommended if you use OTP 20
20.1 ✔️
20.0 ✔️
19.3 ✔️ Recommended if you use OTP 19
19.2 ✔️
19.1 ✔️
19.0 ✔️
18.3 ✔️ Recommended if you use OTP 18
18.2.1 ✔️
18.2 ✔️
18.1 ✔️
18.0 ✔️

A simple way to use, is include in your project rebar.config the following dependency line:

    {ephp_mysql, {git, "git://github.com/bragful/ephp_mysql.git", master}}

And use the following code in your project:

{ok, Ctx} = ephp:context_new(),
ephp:register_module(Ctx, ephp_lib_vars),
ephp:register_module(Ctx, ephp_lib_mysqli),
PHP = "<?php "
      "$id = mysqli_connect(\"localhost\", \"root\", \"root\", \"ephp_mysql\"); "
      "var_dump(mysql_fetch_all(mysqli_query($id, 'SELECT 100')));"
      "mysqli_close($id);",
{ok, Text} = ephp:eval(Ctx, PHP).

The result stored in Text should be:

array(1) {
  [0]=>
  array(1) {
    [0]=>
    string(3) "100"
  }
}
{ok,false}

Enjoy!

Modules

ephp_class_mysqli
ephp_class_mysqli_result
ephp_lib_mysqli
ephp_mysql