寻找一个带有描述的简单 mySQLi 类示例
我正在寻找一个简单但实用的示例,该示例是在 PHP5 中扩展 mySQLi 类的类。 我也对存储过程感兴趣。 基本上我需要的是一个实用且可用的类的示例。 我通过例子学习得最好,不幸的是我无法找到任何网站或书籍似乎有一个真正可靠但简单的例子。 我看到的所有示例都非常复杂,因此我无法理解,或者它们非常简单,我不妨立即实例化该类。 如果有人能为我提供一个这样的例子并尽可能地解释发生了什么,那就太好了。 我的长期目标是拥有一个可以实例化的类,它处理数据库的身份验证,然后获取 SQL 语句并提供变量中的输出。
如果有人愿意花时间帮助我,我将不胜感激! ,谢谢
I am looking for an example of a simple, but functional example of a class extending the mySQLi class in PHP5. I am interested in stored procedures also. Basically what I need is an example of a practical and usable class. I learn best by example and unfortunately I have been unable to find any site or book that seems to have a really solid yet simple example. All the examples I see are way to complicated so I am unable to understand or they are so simple that I might as well just instantiate the class right then and there inline. It would be great if somebody could supply me with an example like this and explain whats going on however well they can. My long term goal is to have a class that I can instantiate that deals with authentication of the database and then takes my SQL statements and supplies the output in variables.
If anyone is willing to take the time to help me out it would be much appreciated!
,Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您检查过 PHP PEAR MDB2 吗?
http://pear.php.net/package/MDB2
它不是那么简单,它是php 中最好的 DAL 恕我直言...
Did you check
PHP PEAR MDB2
?http://pear.php.net/package/MDB2
Its not so simple, its the best DAL in php IMHO...
关于mysqli,你可以看看这些文章:
(相当老了,但是 mysqli 扩展几年来没有太大变化,所以这些应该还可以)
您也可以看看 PDO,自 PHP 5.1 版本起包含在其中; 它是一个面向对象的 API,用于访问多个数据库引擎(您不使用 mysqli_query、pg_query、oci8_query 或类似的东西;仅使用 $pdo->query —— 好吧,您的 SQL 必须兼容,但这是另一个问题; -( )
例如 Doctrine。
另一种方法是使用 ORM , 扩展 MySQLi 的类,而是一个抽象数据库引擎的完整框架 - 使用它,您可以编写一个模式来描述数据库的结构,然后使用“伪 SQL”语言来发送查询或只是(对于大多数情况);抽象 SQL 的面向对象的 API
起初使用起来有点困难,但非常强大且有用(我认为,对于许多类型的项目来说,这对生产力来说并不坏) 。
About mysqli, you can take a look at those articles :
(Quite old, but mysqli extension has not changed that much for a couple of years, so those should still be OK)
You could also have a look at PDO, included in PHP since version 5.1 ; it's an object-oriented API to access multiple DB engines (you don't use mysqli_query, pg_query, oci8_query or stuff like that ; only $pdo->query -- well, your SQL has to be compatible, but that's another problem ;-( )
Another approach would be using an ORM, like, for instance, Doctrine.
It's not a class that extends MySQLi, but a full Framework to abstract the DB engine - with that, you write a schema to describe you DB's structure, and you then use a "pseudo-SQL" language to send queries ; or just (for most cases) the object-oriented API that abstracts SQL.
It's a bit difficult to use, at first, but really powerful and useful (and not bad for productivity, I think, for many kind of projects)
尝试一下 DALMP:http://code.google.com/p/dalmp/支持准备好的语句和许多缓存后端
give a try to DALMP: http://code.google.com/p/dalmp/ is support prepared statements and many cache backends
有点偏离主题,但为什么选择 MySQLi? PDO 更好,现在被认为是事实上的 PHP 标准。 我一两年前写了一个简单的 PDO 类,如果有兴趣我可以给你链接。
Little bit off topic but why MySQLi? PDO is much better and considered a defacto PHP standard these days. I wrote a simple PDO class a year or two ago, I can give you link if interested.
下面是一个向 mysqli 类添加内置查询计时的简单示例。
这假设您已经定义了一个实现 iTimer 接口的“MyTimer”类。 iTimer 类以其最简单的形式记录指定 $key 的开始和停止时间(使用 microtime() 或 getrusage() 或其他方法)。
Here is a simple example of adding built in query timing to the mysqli class.
This assumes you have defined a "MyTimer" class implementing the iTimer interface. iTimer class, in it's simplest form, would record the start and stop times for the specified $key (using microtime() or getrusage() or whatever).