开发者

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 mysq开发者_开发百科l class which can be used to develop my php website?

Thanks.


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.


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.


MySQLI, it the default mysql class libary..


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/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜