什么是Apache的需要同时支持的mysqli和PDO? [英] What does Apache need to support both mysqli and PDO?

查看:170
本文介绍了什么是Apache的需要同时支持的mysqli和PDO?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

PDO 进行数据库访问,而不是的mysqli (因为PDO语法使得我更有意义,是数据库无关)。要做到这一点,我需要这两种方法的工作,而我做的转换。

I'm considering changing some PHP code to use PDO for database access instead of mysqli (because the PDO syntax makes more sense to me and is database-agnostic). To do that, I'd need both methods to work while I'm making the changeover.

我的问题是这样的:到目前为止,无论是一个或其他方法将崩溃的Apache

现在,我在Windows XP和PHP版本5.2.8使用XAMPP。 mysqli的正常工作,所以做到这一点:

Right now I'm using XAMPP in Windows XP, and PHP Version 5.2.8. Mysqli works fine, and so does this:

$dbc = new PDO("mysql:host=$hostname;dbname=$dbname", $username, $password);
echo 'Connected to database';
$sql = "SELECT * FROM `employee`";

不过,此行让Apache的崩溃:

But this line makes Apache crash:

$dbc->query($sql);

我不希望重做我的整个Apache或XAMPP安装,但我想为PDO工作。所以,我想更新的libmysql.dll 来自的这里,因为oddvibes建议这里。这让我简单的 PDO 查询工作,但随后的mysqli 查询崩溃的Apache。

I don't want to redo my entire Apache or XAMPP installation, but I'd like for PDO to work. So I tried updating libmysql.dll from here, as oddvibes recommended here. That made my simple PDO query work, but then mysqli queries crashed Apache.

(我也试过的建议,一个后,更新 php_pdo_mysql.dll php_pdo.dll ,以没有影响。)

(I also tried the suggestion after that one, to update php_pdo_mysql.dll and php_pdo.dll, to no effect.)

我创造了这个测试脚本来比较PDO VS的mysqli。随着的libmysql.dll 的旧副本,它崩溃,如果 $ use_pdo 是真实的,不,如果它是假的。随着的libmysql.dll 的新副本,这是相反的。

I created this test script to compare PDO vs mysqli. With the old copy of libmysql.dll, it crashes if $use_pdo is true and doesn't if it's false. With the new copy of libmysql.dll, it's the opposite.

if ($use_pdo){
  $dbc = new PDO("mysql:host=$hostname;dbname=$dbname", $username, $password);
  echo 'Connected to database<br />';
  $sql = "SELECT * FROM `employee`";
  $dbc->query($sql);
  foreach ($dbc->query($sql) as $row){
    echo $row['firstname'] . ' ' . $row['lastname'] . "<br>\n";
  }

}
else {
  $dbc = @mysqli_connect($hostname, $username, $password, $dbname) OR die('Could not connect to MySQL: ' . mysqli_connect_error());
  $sql = "SELECT * FROM `employee`";
  $result = @mysqli_query($dbc, $sql) or die(mysqli_error($dbc));

  while ($row = mysqli_fetch_array($result,MYSQLI_ASSOC)) {
    echo $row['firstname'] . ' ' . $row['lastname'] . "<br>\n";
    }
}

什么是Apache的需要,以支持数据库查询的两种方法?

推荐答案

不是一个直接的答案,但也许它可以帮助你在寻找它:

Not a direct answer, but perhaps it can help you in your search for it:

遗留MySQL扩展(功能$ P $与的mysql _ pfixed)是一个瘦包装过的libmysqlclient。新的mysqli扩展在本质上是相同的,但它实现了在中的libmysqlclient更高版本中引入的一些功能。 PDO也使用的libmysqlclient,但不作为直接作为其它附加信息做映射。这一切就相当于3个不同的PHP扩展,都指向同一个机库。如果他们中的一些做出关于库的版本假设,这可能导致他们发生冲突。

The legacy mysql extension (The function prefixed with mysql_) is a thin wrapper over libmysqlclient. The new mysqli extension is essentially the same, but it implements some functionality that were introduced in later versions of libmysqlclient. PDO also uses libmysqlclient, but doesn't map it as directly as the other extensions do. This all amounts to 3 different php-extensions that all refer to the same native library. If some of them make assumptions about the version of the library, it might cause them to clash.

我建议你安装 libmysqlclient.dll 的最新版本,你可以找到和尝试禁用旧版mysql扩展(如果你还没有的话)。

I would suggest that you install the newest version of libmysqlclient.dll that you can find and try to disable the legacy mysql extension (if you haven't already).

如果您有使用mysql扩展code,你可以有mysqli的绑定到这些功能,它应该工作一样。

If you have code that uses mysql extension, you can have mysqli bind to those functions and it should work the same.

此外,请确保您没有安装出于某种原因,新mysqlnd驱动程序。 mysqlnd是另一种实现的libmysqlclient的,它真的只是让一切变得更加复杂。

Also, make sure that you don't have the new mysqlnd driver installed for some reason. mysqlnd is an alternative implementation of libmysqlclient and it really just makes everything even more complicated.

是的,这是一个很大的混乱。

Yes, it's a big mess.

这篇关于什么是Apache的需要同时支持的mysqli和PDO?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆