Inserting PHP code into mysql as part of the query

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
tahseenzafar
Forum Newbie
Posts: 2
Joined: Fri Jul 22, 2005 5:23 pm

Inserting PHP code into mysql as part of the query

Post by tahseenzafar »

Hey Guys,
this problem is making me go nuts.
I am trying to do
$query= "insert into page(content) VALUES ('<? include('main.php'); ?> ');
now i know that doesnt work, But i have tried putting in character code for the question mark, the quotes..nothing works.
can you tell me how i can make this work? it works fine on phpMyAdmin
thanks
sincerely,
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

If you want to contents of the document:

Code: Select all

$contents = file_get_contents('main.php');
If you want the parsed output of the document:

Code: Select all

ob_start();
include('main.php');
$contents = ob_get_contents();
After that santize it

Code: Select all

$contents = mysql_real_escape_string($contents);
jmut
Forum Regular
Posts: 945
Joined: Tue Jul 05, 2005 3:54 am
Location: Sofia, Bulgaria
Contact:

Post by jmut »

I guess your question is quoting problem?
Try this:

Code: Select all

$query = 'INSERT INTO page(content) VALUES '. include ('main.php');.'';
Note: Quotes at the and is ' ' and not ".
You don't need to open another php tag.
Post Reply