Archive for June, 2008

How to Include a File in PHP

Posted in Uncategorized on June 28, 2008 by Joey

To include a file from within a PHP file, use the following:

<?php include(“myfile.php”); ?>

MySQL SHOW CREATE PROCEDURE: Outputting the Text of a Stored Procedure

Posted in Uncategorized on June 26, 2008 by Joey

To output the text of a stored procedure in MySQL, use the SHOW CREATE PROCEDURE command, as follows:

SHOW CREATE PROCEDURE MyProc

How to Call a Stored Procedure in PHP

Posted in Software, Technology, php, programming with tags , , , , on June 25, 2008 by Joey

I’m new to PHP. One of the first things I wanted to figure out was how to call a stored procedure in PHP. After some research, I found that the following works. I’m not sure if it’s the best way to do it, so if anyone has some better tips, please comment. (This example is passing the username and password from a form post into a stored procedure.)

define(‘CLIENT_MULTI_RESULTS’, 131072);

$conn = mysql_connect(“hostname”, “username”, “password”, 1 , CLIENT_MULTI_RESULTS)
or die(mysql_error());

mysql_select_db(“datasource”) or die(mysql_error());

$user = $_POST["Username"];
$pass = $_POST["Password"];
$query = mysql_query(“call MyProce(‘$user’,'$pass’)”) or die( mysql_error() );

if (mysql_numrows($query) != 0){
echo ‘query returned results’;
}
else {
echo ‘query returned no results’;
}