summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavey Shafik <me@daveyshafik.com>2016-03-10 15:43:58 -0800
committerDavey Shafik <me@daveyshafik.com>2016-03-10 15:46:47 -0800
commit619fbc986112d603fa9c0db4538454ec71f57e7c (patch)
tree781781aac093ab7eace396ed6005a432c7a7e807
parent9116bd25729b60cf35d939d3fa2aa50ed577e7c8 (diff)
downloadphp7-mysql-shim-619fbc986112d603fa9c0db4538454ec71f57e7c.zip
php7-mysql-shim-619fbc986112d603fa9c0db4538454ec71f57e7c.tar.gz
php7-mysql-shim-619fbc986112d603fa9c0db4538454ec71f57e7c.tar.bz2
Reset field pointer before iterating
Fixes #7
-rw-r--r--lib/mysql.php1
-rw-r--r--tests/MySqlShimTest.php50
2 files changed, 51 insertions, 0 deletions
diff --git a/lib/mysql.php b/lib/mysql.php
index 1fd65d6..0d5a66b 100644
--- a/lib/mysql.php
+++ b/lib/mysql.php
@@ -235,6 +235,7 @@ namespace {
list($table, $name) = explode(".", $field);
$i = 0;
$found = false;
+ mysqli_field_seek($result, 0);
while ($column = mysqli_fetch_field($result)) {
if ($column->table == $table && $column->name == $name) {
$field = $i;
diff --git a/tests/MySqlShimTest.php b/tests/MySqlShimTest.php
index b638f89..070cc5f 100644
--- a/tests/MySqlShimTest.php
+++ b/tests/MySqlShimTest.php
@@ -146,6 +146,18 @@ class MySqlShimTest extends \PHPUnit_Framework_TestCase
);
$this->assertTrue($result, mysql_error());
+
+ $result = mysql_query(
+ "INSERT INTO
+ testing2 (one, two, three, four, five, six, seven, eight, nine, ten, eleven)
+ VALUES
+ ('1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1'),
+ ('2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2'),
+ ('3', '3', '3', '3', '3', '3', '3', '3', '3', '3', '3'),
+ ('4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4')"
+ );
+
+ $this->assertTrue($result, mysql_error());
}
public function test_mysql_query()
@@ -640,6 +652,20 @@ class MySqlShimTest extends \PHPUnit_Framework_TestCase
mysql_result($result, 1, 0);
}
+ /**
+ * @see https://github.com/dshafik/php7-mysql-shim/issues/7
+ */
+ public function test_mysql_result_multiple_calls()
+ {
+ $this->getConnection();
+
+ $result = mysql_query("SELECT * FROM testing LIMIT 1");
+ $this->assertResult($result);
+
+ $this->assertEquals(1, mysql_result($result, 0, 'testing.one'));
+ $this->assertEquals(1, mysql_result($result, 0, 'testing.one'));
+ }
+
public function test_mysql_close()
{
mysql_connect(static::$host, 'root');
@@ -1009,6 +1035,30 @@ class MySqlShimTest extends \PHPUnit_Framework_TestCase
) CHARACTER SET latin1;"
);
+ $result = mysql_query(
+ "CREATE TABLE IF NOT EXISTS testing2 (
+ id int AUTO_INCREMENT,
+ one varchar(255),
+ two varchar(255),
+ three varchar(255),
+ four varchar(255),
+ five varchar(255),
+ six varchar(255),
+ seven varchar(255),
+ eight varchar(255),
+ nine ENUM('one', 'two', '\'three'),
+ ten SET('one', 'two', '\'\'three'),
+ eleven MEDIUMTEXT,
+ INDEX one_idx (one),
+ UNIQUE INDEX two_unq (two),
+ INDEX three_four_idx (three, four),
+ UNIQUE INDEX four_five_unq (four, five),
+ INDEX seven_eight_idx (seven, eight),
+ UNIQUE INDEX seven_eight_unq (seven, eight),
+ PRIMARY KEY (id)
+ ) CHARACTER SET latin1;"
+ );
+
if ($db !== null) {
$this->assertTrue(mysql_select_db($db));
}