How to get mysqli to allow SQL-based User-Defined Variables as column aliases?
[email protected] (Philip Schlesinger) Thu, 10 Jun 2021 05:22:11 +0000
| Newsgroups | php.db |
|---|---|
| Message-ID | <BY5PR17MB355516CC9CE6A653658921DAAE359@BY5PR17MB3555.namprd17.prod.outlook.com> |
--_000_BY5PR17MB355516CC9CE6A653658921DAAE359BY5PR17MB3555namp_ Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: quoted-printable Hi all, I=92m able to get mysqli to set a user-defined variable and the use it late= r on either in a column value definition or a conditional, I.e. (semi-pseud= ocode since I=92m not in front of my work computer) First do mysqli $conn->query(=91Set @foo =3D =93bar=94;=92); =85which will prepare the database session with the variable. Then do a $stmt =3D $conn->stmt_init() Then do a $stmt->prepare(=91Select @foo as =93baz=94;=92); Finally do a $stmt->execute(); That results in: =91baz=92 =97=97=97 =93bar=94 _however_ if I want to use a SQL user-defined variable as a column alias, m= ysqli throws an error. This does not work: $conn->query(=91set @acolname =3D =93aCol=94;=92); $stmt =3D $conn->stmt_init() $stmt->prepare(=91Select =93data=94 as @acolname;=92); $stmt->execute(); If I ran the straight SQL in a SQL application, making the select statement= a variable as well, and did a prepare and execute, it would work just fine Mysqli however throws an error with the column alias being a SQL user-defin= ed variable. Help? Get Outlook for iOS<https://aka.ms/o0ukef> --_000_BY5PR17MB355516CC9CE6A653658921DAAE359BY5PR17MB3555namp_--