include PHP script from MyQSL database

  • Zielak69
  • Novice
  • Novice
  • Zielak69
  • Posts: 21
  • Loc: Poland

Post 3+ Months Ago

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() ?
  • mishka
  • Novice
  • Novice
  • mishka
  • Posts: 20
  • Loc: Toronto

Post 3+ Months Ago

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

Just the way of thinking to utilize DB engine to store scripts is unappropriated from conceptual POV ...
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13504
  • Loc: Florida

Post 3+ Months Ago

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.
  • Zielak69
  • Novice
  • Novice
  • Zielak69
  • Posts: 21
  • Loc: Poland

Post 3+ Months Ago

Ok, I guess I'll do it with include, thanks for advices.
  • msj1013
  • Novice
  • Novice
  • msj1013
  • Posts: 24

Post 3+ Months Ago

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

http://us.php.net/eval
  • gkumar
  • Beginner
  • Beginner
  • gkumar
  • Posts: 39

Post 3+ Months Ago

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
  • sandy_j_sam
  • Posts: 9

Post 3+ Months Ago

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: No registered users and 97 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
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.