0

I'm wondering if there is a way to run explicit SQL strings inside of PHP. I know PHP has a bunch of handling methods (sql_connect(...) is an example; however I have memories of using LINQ in C# and being able to run specific, concatenated strings as literal SQL.

Does anyone happen to know of a way to do that using PHP?

An example of a query I'd want to run:

SELECT p.id, p.name, numberOfPosts, posts.subject
FROM Persons p
INNER JOIN Posts posts ON posts.personID = p.ID
WHERE id = @currentUser;

where "@currentUser" would be a variable that would be set to a currently logged in user on a PHP-based site.

Thanks ahead of time for any help!

4

1 に答える 1

2

あなたの例を見ると、 PDOプリペアドステートメントを利用するのが最善でしょう。

于 2012-09-25T15:23:54.887 に答える