tags:

views:

221

answers:

4

Why does this pdo::mysql code crash on 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();
} 

?>

basically this line of code is what triggers Apache to crash..

    $sql = "SELECT * FROM vCard";

If I try to select one value like 'id' it'll ... when I try to select more than one value "*" it crashes??????

A: 

Same here with Apache2 PHP 5.2.12 / LibMySQL 5.1.44 and 5.1.42 ... with OllyDBG, we can see the crash happens in php_pdo_mysql

after first column name analysis... i see first column "ID_Utilisateur" in stack

near "ext\pdo_mysql\mysql_statement.c"

LibMySQL is the good one (php dir), all is VC6 compiled here...

<?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

...

crash at eip 002C249A

Tanguy
working with "select ID_Utilisateur from utilisateurs" query
Tanguy
[Sun Mar 14 19:47:37 2010] [notice] EACCELERATOR(81656): PHP crashed on opline 16 of query() at W:\web\pdo_test\index.php:7[Sun Mar 14 19:47:37 2010] [crit] Parent: child process exited with status 3 -- Aborting.
Tanguy
not related to EACCELERATOR and XDEBUG
Tanguy
and also with php command line...
Tanguy
same here : http://stackoverflow.com/questions/1625895/what-does-apache-need-to-support-both-mysqli-and-pdo/2443494#2443494
Tanguy
happens before estrndup() call in ext\pdo_mysql\http://github.com/php/php-src/blob/4f3e41e55dae1978487461d73805eaac8202aff8/ext/pdo_mysql/mysql_statement.c#L450
Tanguy
A: 

The unique solution i found :

Install LibMySQL.DLL FROM 5.0.51a package (working with last 5.1.44 MySQL Version)

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

Tanguy
A: 

Ok, i have a very bad but working solution :p)

Open ext\php_pdo_mysql.dll with an Hex Editor

Search for "83 C3 50" offset 0x000024d5 (in php 5.2.12 vc6)

Replace by 83 C3 "54"

The problem is a bad structure size... (struct pdo_column_data)

I tried to fix that in libmysql.dll but that crash php_mysqli ;)

Tanguy
...3 separate answers, the last one being to directly edit the DLL itself? I'd check for a second opinion before accepting this.
Matchu
Patching an executable? A blast from the past...
Brian Hooper
A: 

The right way is to recompile mysql mysqli and pdo_mysql php modules with the good mysql headers (from mysql sources)

But setting up the good dev environment is hard (Windows SDK, VC6 command line, and all needed libs)

In fact, there are protocol versions (you can see in mysql headers, a file named version.h).

I make that for my WAMP package, named EWS - Easy Web Server, for each new release

Tanguy