xkeshav
xkeshav

Reputation: 54016

good mysql class for php website?

I was using ezmysql class initially for mysql operations, but that is not updated.

So i want to know is there any easy and well documented mysql class which can be used to develop my php website?

Thanks.

Upvotes: 0

Views: 1744

Answers (4)

Rho
Rho

Reputation: 1010

Go for PDO. Although PDO is harder to learn. But is more secure and more portable. I use it myself, here's a sample query

try {
$id = 1;
$db = new PDO("mysql:host=$this->hostname;dbname=test", $this->username, $this->password);
$db->setAttribute(PDO::ATTR_ERRORMODE, PDO::ERRMODE_WARNING);

$stmt = $db->prepare("SELECT * FROM test WHERE id=:id");
//note that you need your variables set before you can bind it.
$stmt->bindParam(":id", $id);
$stmt->execute();
//similar to $mysqli->fetchAll()
$stmt->fetchAll();
} catch(Exception $e) {
echo $e->getMessage();
}

Hopefully you like how PDO works.. it is more secure for your queries. Additionally you can use PDO for Updating and Inserting queries too.

Here's some tutorial for you to start using PDO: http://net.tutsplus.com/tutorials/php/why-you-should-be-using-phps-pdo-for-database-access/

Upvotes: 0

Pascal MARTIN
Pascal MARTIN

Reputation: 400932

Other answers suggested using MySQLi -- which is a good solution.

Another good solution would be working with PDO (which supports MySQL, of course, but also helps working with other DB engines).

Else, if you need a more complex (but powerful, once you know it) system, you could go with an ORM layer, such as Doctrine or Propel.

Upvotes: 3

code_burgar
code_burgar

Reputation: 12323

Contrary to the popular "Don't reinvent the wheel" wisdom, I would really suggest writing your own DB abstraction class if the built in stuff like aforementioned MySQLi class doesn't suit your needs.

Upvotes: 4

Yoram de Langen
Yoram de Langen

Reputation: 5499

MySQLI, it the default mysql class libary..

Upvotes: 2

Related Questions