include PHP script from MyQSL database

  • Zielak69
  • Novice
  • Novice
  • No Avatar
  • Joined: Jun 25, 2008
  • Posts: 21
  • Loc: Poland
  • Status: Offline

Post December 1st, 2008, 12:38 pm

So here's the thing.
I've put my php script into a database as 'longtext' and I want it to be compiled by PHP. Right now it just shows me the script as simple non-compilated text. For example:
PHP Code: [ Select ]
<?
// script to get a row from db with html and php script
// the variable that is holding it is $f and it contains something like:
// <b><? echo $a; ?></b>
$a = 'hello there';
 
echo $f;
 
?>
  1. <?
  2. // script to get a row from db with html and php script
  3. // the variable that is holding it is $f and it contains something like:
  4. // <b><? echo $a; ?></b>
  5. $a = 'hello there';
  6.  
  7. echo $f;
  8.  
  9. ?>

The output should be
PHP Code: [ Select ]
<b>hello there</b>


Is that possible to do? Or is there any other way of doing it?

.. or should I simply put that scripts in .php files and use include() ?
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post December 1st, 2008, 12:38 pm

  • mishka
  • Novice
  • Novice
  • No Avatar
  • Joined: May 28, 2005
  • Posts: 20
  • Loc: Toronto
  • Status: Offline

Post December 1st, 2008, 12:51 pm

Oh man ... use include()...

Just the way of thinking to utilize DB engine to store scripts is unappropriated from conceptual POV ...
  • joebert
  • Sledgehammer
  • Genius
  • No Avatar
  • Joined: Feb 10, 2004
  • Posts: 13455
  • Loc: Florida
  • Status: Offline

Post December 1st, 2008, 1:39 pm

File includes/requires is the way I would go.

Something like XCache can cache the opcode for the file includes, whereas even if you use memcached to reduce the load on the database, you'ld still have to exec() the script every time.
Strong with this one, the sudo is.
  • Zielak69
  • Novice
  • Novice
  • No Avatar
  • Joined: Jun 25, 2008
  • Posts: 21
  • Loc: Poland
  • Status: Offline

Post December 1st, 2008, 1:48 pm

Ok, I guess I'll do it with include, thanks for advices.
  • msj1013
  • Novice
  • Novice
  • No Avatar
  • Joined: May 06, 2007
  • Posts: 24
  • Status: Offline

Post December 14th, 2008, 10:21 pm

You can also use the eval() function in php to evaluate code.

http://us.php.net/eval
  • gkumar
  • Beginner
  • Beginner
  • No Avatar
  • Joined: Jul 28, 2009
  • Posts: 39
  • Status: Offline

Post July 30th, 2009, 1:38 am

If you want to access MySQL database server in your PHP script, you need to make sure that MySQL module is installed and turned on in your PHP engine. Check the PHP configuration file, php.ini, to make sure the extension=php_mysql.dll is not commented out.

The MySQL module offers a number of functions to allow you to work with MySQL server. Some commonly used MySQL functions are:

* mysql_connect -- Open a connection to a MySQL Server
* mysql_close -- Close MySQL connection
* mysql_db_query -- Send a MySQL query
* mysql_fetch_array -- Fetch a result row as an associative array, a numeric array, or both
* mysql_free_result -- Free result memory
* mysql_list_tables -- List tables in a MySQL database
* mysql_list_fields -- List MySQL table fields
  • sandy_j_sam
  • Newbie
  • Newbie
  • No Avatar
  • Joined: Jul 26, 2010
  • Posts: 9
  • Status: Offline

Post July 28th, 2010, 11:15 pm

Hi, As we know that php is a server side scripting language, means no way that, it's program run without server, i.e on local browser, then you first install server, like Apache, see them
[WAMP] => window + Apache Server + MySql + php.
Now I mention here Editor like Adobe Dream Weaver, where you write code having extension is .php,
now you save it in root folder
Path : C:/D:/E:/F:/ = >wamp => www => you create folder(Like php app.) =>script.php

<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
if (mysql_query("CREATE DATABASE db_name",$con))
{
echo "Database created";
}
else
{
echo "Error creating database: " . mysql_error();
}
mysql_select_db("samlple_db_table", $con);
$sql = "CREATE TABLE table_name1
(
FName varchar(15) NOT NULL,
LName varchar(15) NOT NULL,
)";
mysql_query($sql,$con);
mysql_close($con);
?>

Post Information

  • Total Posts in this topic: 7 posts
  • Users browsing this forum: ScottG and 242 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.