为什么这个pdo :: mysql代码在Windows上崩溃了?

时间:2009-08-11 03:03:45

标签: php mysql pdo

为什么这个pdo :: mysql代码在Windows上崩溃???

<?php
$username = "root";
$password = "";

try {
    $dsn = "mysql:host=localhost;dbname=employees";
    $dbh = new PDO($dsn, $username, $password);
    $dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, FALSE);
    $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

echo "Connected to database<br />" ;

$dbh->exec("DROP TABLE IF EXISTS vCard;");
$dbh->exec("DROP TABLE IF EXISTS emp;");

$table = "CREATE TABLE vCard(
    id INT(4) NOT NULL PRIMARY KEY, 
    firstName VARCHAR (255), 
    lastName VARCHAR (255), 
    office VARCHAR (255), 
    homePh VARCHAR (13), 
    mobilePh VARCHAR (13))";

$dbh->exec($table);

$dbh->beginTransaction();

$dbh->exec("INSERT INTO vCard(id, firstName, lastName, office, homePh, mobilePh)
    VALUES (4834, 'Randy', 'Lewis', 'SR. Front End Developer', '631-842-3375', '917-435-2245');");

$dbh->exec("INSERT INTO vCard(id, firstName, lastName, office, homePh, mobilePh)    
    VALUES (0766, 'Frank', 'LaGuy', 'Graphic Designer', '631-789-8244', '917-324-9897');");

$dbh->exec("INSERT INTO vCard(id, firstName, lastName, office, homePh, mobilePh)    
    VALUES (6684, 'Donnie', 'Dolemite', 'COO', '631-789-9482', '917-234-1222');");

$dbh->exec("INSERT INTO vCard(id, firstName, lastName, office, homePh, mobilePh)    
    VALUES (8569, '', 'McLovin', 'Actor', '631-842-9786', '917-987-8944');");

$dbh->commit();

echo "Data entered successfully<br/><br/>";

    $sql = "SELECT * FROM vCard"; // WHERE firstName = 'Donnie'";

    $results = $dbh->query($sql);

    foreach ($results as $id){
        echo "SSN: ". $id['id']." ";
        echo "First Name: ". $id['firstName']." ";
        echo "Last Name: ". $id['lastName']."<br/>";
    }

}   
catch (PDOException $e) {
    echo "Failed: " . $e->getMessage();
    $dbh->rollback();
}   

?>

基本上这行代码是导致Apache崩溃的原因..

    $sql = "SELECT * FROM vCard"; 

如果我尝试选择一个像'id'这样的值,那么......当我尝试选择多个值“*”时,它会崩溃??????

4 个答案:

答案 0 :(得分:1)

我找到了独特的解决方案:

安装LibMySQL.DLL FROM 5.0.51a包(使用最新的5.1.44 MySQL版本)

http://www.netfulvpc.fr/files/libmysql_dll.zip

答案 1 :(得分:1)

好的,我有一个非常糟糕但有效的解决方案:p)

使用十六进制编辑器打开ext \ php_pdo_mysql.dll

搜索“83 C3 50”偏移量0x000024d5(在php 5.2.12 vc6中)

替换为83 C3“54”

问题是结构大小不好......(struct pdo_column_data)

我试图在libmysql.dll中修复它,但崩溃了php_mysqli;)

答案 2 :(得分:0)

与Apache2 PHP 5.2.12 / LibMySQL 5.1.44和5.1.42相同... 使用OllyDBG,我们可以看到崩溃发生在php_pdo_mysql

在第一列名称分析后...我在堆栈中看到第一列“ID_Utilisateur”

靠近“ext \ pdo_mysql \ mysql_statement.c”

LibMySQL是好的(php dir),这里都是VC6编译的......

<?php

$dbh = new PDO('mysql:host=127.0.0.1;port=3306;dbname=uba_dev','root','');

echo "ok";
$dbh->exec('SET CHARACTER SET latin1');

echo "ok";
$stmt = $dbh->query("select * from utilisateurs"); <<< CRASH HERE

...

在eip 002C249A崩溃

答案 3 :(得分:0)

正确的方法是使用好的mysql头文件(来自mysql源代码)重新编译mysql mysqli和pdo_mysql php模块

但是设置良好的开发环境很困难(Windows SDK,VC6命令行和所有需要的库)

实际上,有协议版本(你可以在mysql头文件中看到一个名为version.h的文件)。

我为每个新版本命名为EWS - Easy Web Server的WAMP包