PHP class for interaction with Mysql BD

Asked

Viewed 430 times

2

Does anyone know any PHP class for Mysql integration, using the function mysqli_* and Prepared statements?

I have these two examples:

  • Tried to use some abstraction like adodb, or a ORM such as the Doctrine?

  • No, I didn’t try.

  • What you really need to do?

  • The normal, insert, remove, update the Mysql BD via PHP. Without always repeating the code, example: $mysqli->prepare($sql);

  • 2

    I think you solve this by writing a simple function, for example in the format JBMySQLi( $query, { $valor1, $valor2, etc } )

  • @Bacco I wanted to avoid repeating the code of prepare, bind_param, etc, whenever I was interacting with the comic book, so I wanted a well-made class that would take care of it all. I’m in the middle of the scale between using a suggested, or making one of my own.

  • I’m creating something from scratch too, for basic queries in Mysql with PHP. If you want to take a look: https://gist.github.com/mervy/595fa971d4cff08bba673e4687ade66e .

Show 2 more comments

4 answers

2

Medoo

I point out the dread (http://medoo.in/) it uses PDO and not mysqli, but has many features: joins, all basic operations, WHERE, AND, and many others[listed in the documentation]. In addition to an excellent security guard and documentation, speeds up development.

It is also very practical and has a reasonable system of errors.

Documentation: http://medoo.in/doc

Download: http://medoo.in/download


But if you really need something advanced I recommend using mysqli / PDO itself and start programming, frameworks streamline and facilitate, but sometimes are very limited.


Note

I indicated a class with PDO because PDO and mysqli have almost the same features and was the best I found, and I highly doubt that their hosting does not support PDO, if not support I suggest switching hosts.

Note 2

That’s just one SUGGESTION, there are several frameworks / classes out there, you can even do yours, but don’t take my opinion as the best or right one (it may even be), but wait for other answers before you mark some as right, because the intention of the OS is to have good answers that can be seen by others in the future, and the range of answers here can be somewhat "broad".

  • 4

    The name is very suggestive.

2

  • 1

    Vagner, it would be possible to elaborate a little the answer, perhaps highlighting some details, advantages and disadvantages on these indications?

1

You can use your own MySQLi

PHP

$db = new mysqli("localhost", "usuario", "senha", "meubanco");

Utilizing

PHP

$resultado = $db->query("SELECT * FROM tabela");
while($row = $resultado->fetch->array()) {
  echo $row["campo"];
}

More information on Manual PHP

  • This I know, is how I use, I wanted was a class with the methods of insertion, removal, update and selection, in a generic way with Prepared statements.

  • 1

    @Jorgeb. The mysqli class itself already does this...

  • @Olimonf. the idea was a class type https://github.com/joshcam/PHP-MySQLi-Database-Class that would facilitate my interaction with the mysqli_

0

If you are going to do it by hand, I advise you to use PDO, functions like mysql_connect and the like, are out of use. More current versions of php already trigger deprecated Warning when they appear in code.

If you want to use some ready lib, recommend http://www.phpactiverecord.org/

  • I use, as referred to in the question, mysqli_

Browser other questions tagged

You are not signed in. Login or sign up in order to post.