Mister R2
Mister R2

Reputation: 881

Explicit SQL in PHP

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!

Upvotes: 0

Views: 67

Answers (1)

Conrad Lotz
Conrad Lotz

Reputation: 8818

Looking at your example the best would be to make use of PDO Prepared-Statements

Upvotes: 2

Related Questions