Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

possible bug with selecting individual columns vs select splat. #18177

Closed
dupes2k opened this issue Mar 29, 2025 · 3 comments
Closed

possible bug with selecting individual columns vs select splat. #18177

dupes2k opened this issue Mar 29, 2025 · 3 comments

Comments

@dupes2k
Copy link

dupes2k commented Mar 29, 2025

Description

The following code:

<?php
// If using an SQL statement like:
$sql = "SELECT * FROM"...

// then you can assign array variables just fine as pulled from your $result->fetch_assoc() in your while loop.

// However if your SQL is like:
$sql = "SELECT my_var1 and my_var2 FROM"...

Resulted in this output:

// then using print_r() on the returned structure shows:
//Array
//{
//     [my_var1 and my_var2] => 0
//}

But I expected this output instead:

// normal array structure as shown with print_r()

PHP Version

php ver 8.2.28

Operating System

Debian 12 (bookworm)

@MorganLOCode
Copy link

Which dialect of SQL is that which uses "and" in that way?

@tcoch
Copy link

tcoch commented Mar 29, 2025

I just tried it and this works for MySQL.

And actually, the PHP output seems fine to me, since I got not two columns but just the one in the query result.

select a, b from table gives you this:

a b
data_a data_b
... ...

while select a and b from table gives you this:

a and b
0
...

@nielsdos
Copy link
Member

This isn't a bug, if you write "a and b" in the select classes then you're evaluating a boolean. You can put expressions in the select clause. You should use a comma.

@nielsdos nielsdos closed this as not planned Won't fix, can't repro, duplicate, stale Mar 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants