且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

不使用mysqlnd返回多行

更新时间:2023-12-04 13:23:34

实际上,PDO比使用mysqlnd的mysqli更容易.

in fact, PDO is WAY easier than mysqli with mysqlnd.

您可以尝试我的PDO包装器,甚至可以使它比原始类更好-使用起来非常简单,将旧的mysql函数的简单性与准备好的语句的强大功能和安全性结合在一起.

You can try my wrapper for PDO which can make it even better than original class - it's incredible simple in use, combining simplicity of old mysql functions with power and safety of prepared statements.

说,要获得多个结果,您将需要一行代码,与使用旧版mysql函数时使用mysqli或使用六个屏幕时的几个屏幕相反:

Say, to get your multiple results you wull need one single line of code, opposite to several screens in case of mysqli or half-dozen when using old mysql functions:

$sql  = 'SELECT return, fields  FROM table WHERE search_field = ?';
$data = DB:prepare($sql)->execute([$search_val])->fetchAll();

现在$ data包含您可以迭代的所需结果

now $data contains the desired result you can iterate over

foreach ($data as $row)
{
     echo $row['fields'];
}

只需在某个位置使用DB凭据定义四个常量,然后就可以在代码中的任何位置使用数据库,就像以前的旧mysql ext一样.

Just define four constants with your DB credentials somewhere and then you'll be able to use database anywhere in your code, just like with old mysql ext used to be.