http://lists.mysql.com/mysql-es/1486rokwell3 dijo:tengo un problemita con mysql y php.
Resulta que estoy probando procedimientos almacenados en mysql, y me funciona bien por consola, pero como hago para llamar ese procedimiento por php? por que probando no me funciona $resultado=mysql_query("call pruebaprocedimiento('3')") y el error que me sale es:
can't return a result set in the given context.
Muchas gracias por adelantado de las pistas que me puedan dar.
PHP 4 end of life announcement
[13-Jul-2007] Today it is exactly three years ago since PHP 5 has been released. In those three years it has seen many improvements over PHP 4. PHP 5 is fast, stable & production-ready and as PHP 6 is on the way, PHP 4 will be discontinued.
The PHP development team hereby announces that support for PHP 4 will continue until the end of this year only. After 2007-12-31 there will be no more releases of PHP 4.4. We will continue to make critical security fixes available on a case-by-case basis until 2008-08-08. Please use the rest of this year to make your application suitable to run on PHP 5.
For documentation on migration for PHP 4 to PHP 5, we would like to point you to our migration guide. There is additional information available in the PHP 5.0 to PHP 5.1 and PHP 5.1 to PHP 5.2 migration guides as well.
rokwell3 dijo:tengo un problemita con mysql y php.
Resulta que estoy probando procedimientos almacenados en mysql, y me funciona bien por consola, pero como hago para llamar ese procedimiento por php? por que probando no me funciona $resultado=mysql_query("call pruebaprocedimiento('3')") y el error que me sale es:
can't return a result set in the given context.
Muchas gracias por adelantado de las pistas que me puedan dar.
/**********************************************************/
archivo sql: prueba_storeprocedure.sql
/**********************************************************/
USE dbprueba;
DROP PROCEDURE IF EXISTS sp_municipio;
delimiter ·
CREATE PROCEDURE sp_municipio (IN var_pais INT, IN var_departamento INT, IN var_municipio INT)
BEGIN
SELECT id_pais,id_departamento,id_municipio,nombre,sigla
FROM municipio
WHERE id_pais=var_pais AND id_departamento=var_departamento AND id_municipio=var_municipio
END
·
delimiter ;
/**********************************************************/
/**********************************************************/
archivo php: prueba_storeprocedure.php
/**********************************************************/
<?php
// fijense en la conexion, es ahi donde esta el trukito
if (!($link=mysql_connect("localhost",$usuario,$password,'',65536))){
print ("Este sitio se encuentra en Mantenimiento");
exit();
}
if (!mysql_select_db("dbprueba",$link)){
print ("Este sitio se encuentra en Mantenimiento");
exit();
}
$p=1;
$d=5;
$m=5001;
if(!($rst_consulta=mysql_query("call sp_municipio('$p','$d','$m')"))){
echo 'Error '.mysql_error();
}
else{
echo 'Numero de registros: '.mysql_num_rows($rst_consulta).'<br>';
while($resultados=mysql_fetch_array($rst_consulta)){
echo $resultados['id_pais'].' - '.$resultados['id_departamento'].' - '.$resultados['id_municipio'].
' - '.$resultados['nombre'].' - '.$resultados['sigla'].'<br>';
}
}
?>
/**********************************************************/
1<?php
2
3/*
4This class represents a connection to MySQL databases. Provides the following ehavior:
5
6- Open connection
7- Execute Query
8- Close connection
8- Get number of query result rows
9- Free result set
10- Iterate over query result rows
11
12@author :
13@year: 2005
14*/
15require_once("DBConfig.inc.php");
16
17class MySQLConnection{
18
19//----------------------------------------
20 // Attributes
21
22 //server hostname
23 var $host;
24
25 //database name
26 var $database;
27
28 //server user
29 var $user ;
30
31 //user passwd
32 var $passwd ;
33
34 //server port
35 var $port;
36
37 //query result
38 var $result;
39
40 //connection link
41 var $link;
42
43 //----------------------------------------
44 // Constructor
45
46 function MySQLConnection(){
47
48 $this->setHost(DBConfig::$HOST);
49 $this->setDatabase(DBConfig::$DATABASE);
$this->setUser(DBConfig::$USER);
$this->setPasswd(DBConfig::$PASSWD);
$this->setPort(DBConfig::$PORT);
}
//----------------------------------------
// Destructor
function _destructor(){
$this->closeConnection();
$this->freeResult();
}
//----------------------------------------
// Getter methods
function getHost(){
return $this->host;
}
function getDatabase(){
return $this->database;
}
function getUser(){
return $this->user;
}
function getPasswd(){
return $this->passwd;
}
function getPort(){
return $this->port;
}
function getResult(){
return $this->result;
}
//----------------------------------------
// Setter methods
function setHost($_host){
$this->host = $_host;
}
function setDatabase($_database){
$this->database = $_database;
}
function setUser($_user){
$this->user = $_user;
}
function setPasswd($_passwd){
$this->passwd = $_passwd;
}
function setPort($_port){
$this->port = $_port;
}
//----------------------------------------
// Methods
/*
This method opens a database connection
*/
function openConnection(){
$this->link = mysql_connect($this->host, $this->user, $this->passwd);
if( $this->link ){
mysql_select_db($this->database,$this->link);
}else{
$this->error_handler( mysql_errno(), mysql_error() );
}
}
/*
This method executes the query given as parameter
*/
function execute($query){
//$this->result = mysql_query($query)or die(mysql_error());
$this->result = mysql_query($query);
if( !$this->result ){
$this->error_handler( mysql_errno(), mysql_error() );
}
}
/*
Get next query result row
*/
function nextRow(){
$row = mysql_fetch_array($this->result);
return $row;
}
/*
Get number of rows in result set
*/
function numRows($result){
$numRows = mysql_num_rows($this->result);
return $numRows;
}
/*
Get number of query execution affected rows
*/
function getAffectedRows(){
return mysql_affected_rows();
}
/*
Get the ide generated from the previous INSERT operation
*/
function getInsertId(){
return mysql_insert_id();
}
/*
Close MySQL connection
Returns: TRUE on success or FALSE on failure
*/
function closeConnection(){
return @mysql_close($this->link);
}
/*
Free result memory
Returns: TRUE on success or FALSE on failure
*/
function freeResult(){
return mysql_free_result($this->result);
}
/*
Report Mysql Errors
Allows to report an error with the database without exposing
its structure or technical details about the application.
*/
function error_handler( $errorNumber, $errorMessage ){
$msg = "<b>Error:</b> ";
//echo "No: ".mysql_errno()."<br>";
//echo "Message: ".mysql_error()."<br>";
$flag = true;
switch ( $errorNumber ){
//Llave duplicada
case 1062:
$msg .= "Entrada duplicada<br>";
$flag = false;
break;
//Fallo Integridad Referencial
case 1451:
$msg .= "No se puede ejecutar la consulta por motivos de integridad referencial.<br>";
break;
//No se puede conectar con MySQL
case 2003:
$msg .= "Lo sentimos, no hay conexión disponible con la base de datos.<br>";
break;
default:
$msg .= $errorMessage;
break;
}
if( $flag ){
die($msg);
}else{
echo $msg;
}
}
//End class
}
?>
turkok dijo:<a href='JavaScriptopWindow()'><img src='$row[3]' width='180' height='100' border='0'/></a>
que es este :
<script language="JavaScript" type="text/javascript">
<!--
function PopWindow()
{
window.open('popdetalle.php?var=holllaaaaaa','detalle','width=400,height=300,menubar=no,scrollbars=no,toolbar=no,location=yes,directories=no,resizable=no,top=200,left=350');
}
//-->
</script>
y lo recepciono en la pop up pero no ce como , alguien me puede ayudar por favor , el hecho de que exista una variable llamada var=holllaaaaa es solo por realizaba pruebas a la pop up directamente
AAAYUUUDDDAAAAAAAAAA !!!!!!!!!!!!!!!!!::::::::::::
_________________
Turkoglups esta aprendiendo , no molestar !!!
turkok dijo:lo que en otro foro no se pudo !!! ayudaaa!!!
weno amigos yo siempre con mis problemas evistenciales , pero ahora si no se me ocurre nada , aqui va : yo ocupo una pagina con consultas sql para mostrar datos y en uno de esos registros lo linkeo a una ventana pop up , pero lo que yo quiero es que al momento de pinchar en el registro envie datos por url a la ventana pop up , y debido a que esta pasa por un codigo javascript no se como hacerlo , aqui les pongo el ejemplo
aqui esta el registro el dato es el row y al hacer click este hace referencia al codigo javascript de la ventana pop up
<a href='JavaScriptopWindow()'><img src='$row[3]' width='180' height='100' border='0'/></a>
que es este :
<script language="JavaScript" type="text/javascript">
<!--
function PopWindow()
{
window.open('popdetalle.php?var=holllaaaaaa','detalle','width=400,height=300,menubar=no,scrollbars=no,toolbar=no,location=yes,directories=no,resizable=no,top=200,left=350');
}
//-->
</script>
y lo recepciono en la pop up pero no ce como , alguien me puede ayudar por favor , el hecho de que exista una variable llamada var=holllaaaaa es solo por realizaba pruebas a la pop up directamente
AAAYUUUDDDAAAAAAAAAA !!!!!!!!!!!!!!!!!::::::::::::
_________________
Turkoglups esta aprendiendo , no molestar !!!
<a href="JavaScript:PopWindow($row[3])"><img src="$row[3]" width="180" height="100" border="0"/></a>
<script language="JavaScript" type="text/javascript">
<!--
function PopWindow(laurl)
{
laurl='popdetalle.php?var='+laurl;
window.open('popdetalle.php?var='+laurl,'detalle','width=400,height=300,menubar=no,scrollbars=no,toolbar=no,location=yes,directories=no,resizable=no,top=200,left=350');
}
//-->
</script>
super buena la respuesta compadre de hecho envia los datos pero estoy provando si los puedo extraer con get , otra consulta si yo quisiera enviar 2 variables deberia ser algo asi ''www.sitioweb.com/index.php/var?'+laurl+'&var2='+laurl2rokwell3 dijo:Creo que esto funciona, no lo he probado pero mmm ahi ta
PHP:<a href="JavaScript:PopWindow($row[3])"><img src="$row[3]" width="180" height="100" border="0"/></a> <script language="JavaScript" type="text/javascript"> <!-- function PopWindow(laurl) { laurl=[B][COLOR="Blue"]'popdetalle.php?var='+laurl[/COLOR][/B]; window.open([B][COLOR="blue"]'popdetalle.php?var='+laurl[/COLOR],[/B]'detalle','width=400,height=300,menubar=no,scrollbars=no,toolbar=no,location=yes,directories=no,resizable=no,top=200,left=350'); } //--> </script>
KERBEROS dijo:Señores!! agradezco me recomienden el que a su juicio es el mejor editor PHP. Bueno tambien que me cuente porquen consideran que es tan bueno.
Queda excluido: el Block de Notas (Notepad).
Gracias,
turkok dijo:super buena la respuesta compadre de hecho envia los datos pero estoy provando si los puedo extraer con get , otra consulta si yo quisiera enviar 2 variables deberia ser algo asi ''www.sitioweb.com/index.php/var?'+laurl+'&var2='+laurl2
a y no afecta que des la url 2 veces a una misma variable como los destaco con azul en el codigo
<a href="javascript:PopWindow('popdetalle.php?var=\'+laurl+\'&var2=\'+variable2)"><img src="$row[3]" width="180" height="100" border="0"/></a>
<script languaje="javascript">
function PopWindow(laurl) {
//para verificar el valor que manda
alert(laurl);
window.open(laurl,'detalle','width=400,height=300,menubar=no,scrollbars=no,toolbar=no,location=yes,directories=no,resizable=no,top=200,left=350');
}
</script>
rokwell3 dijo:Men creo que me equivoque por que ese javascript esta mandando dos veces la pagina y los parametros por GET, tonces eso quedaria asi:
PHP:<a href="javascript:PopWindow('popdetalle.php?var=\'+laurl+\'&var2=\'+variable2)"><img src="$row[3]" width="180" height="100" border="0"/></a> <script languaje="javascript"> function PopWindow(laurl) { //para verificar el valor que manda alert(laurl); window.open(laurl,'detalle','width=400,height=300,menubar=no,scrollbars=no,toolbar=no,location=yes,directories=no,resizable=no,top=200,left=350'); } </script>
hola amigo , pucha no es por molestar , pero mira me pasa esto el primer codigo que tu me enviaste lo hice funcionar , detectando eso de enviar la url 2 veces y quedo hacirokwell3 dijo:Men creo que me equivoque por que ese javascript esta mandando dos veces la pagina y los parametros por GET, tonces eso quedaria asi:
PHP:<a href="javascript:PopWindow('popdetalle.php?var=\'+laurl+\'&var2=\'+variable2)"><img src="$row[3]" width="180" height="100" border="0"/></a> <script languaje="javascript"> function PopWindow(laurl) { //para verificar el valor que manda alert(laurl); window.open(laurl,'detalle','width=400,height=300,menubar=no,scrollbars=no,toolbar=no,location=yes,directories=no,resizable=no,top=200,left=350'); } </script>
turkok dijo:hola amigo , pucha no es por molestar , pero mira me pasa esto el primer codigo que tu me enviaste lo hice funcionar , detectando eso de enviar la url 2 veces y quedo haci
<script language="JavaScript" type="text/javascript">
<!--
function PopWindow(laurl)
{
laurl='http://www.agsautomotriz.cl/popdetalle.php?var='+laurl;
window.open(laurl,'detalle','width=450,height=390,menubar=no,scrollbars=no,toolbar=no,location=yes,directories=no,resizable=no,top=200,left=350');
}
//-->
</script>
<a href='javascriptopWindow($row[0])'>
este ultimo codigo el del link esta encerrado en un echo""; dentro de un codigo php , te digo esto por que el ultimo codigo no me resulta el que es para enviar las dos variables me tira un error de recepcion del codigo , ni siquiera habre la popup y eso es por sintaxis supongo , asi que asumo que algo en la sintaxis esta mal del codigo javascript en el link <a> creo yo , pero este funciona (el primero) enviando una variable , pero con dos no , no se que pasa , cambie las comillas dobles por simples e iguale el nombre de var= $row[0] y la var2 = $row[1]
pero , disculpe que lo moleste cumpa pero me tiene esto desesperado..
<?php
echo '<a href="javascript:PopWindow(\'popdetalle.php?var=\'+'.$row[1].'+\'&var2=\'+'.$row[2].')"><img src="'.$row[3].'" width="180" height="100" border="0"/></a>';
?>
rokwell3 dijo:En la parte del vinculo puede presentar problemas por las comillas simples o dobles por haber combinación de php+javascript+parámetros de javascript con php, ese posiblemente sea la razón del error.
Ejemplo del vinculo impreso desde php con todo lo anterior combinado:
PHP:<?php echo '<a href="javascript:PopWindow(\'popdetalle.php?var=\'+'.$row[1].'+\'&var2=\'+'.$row[2].')"><img src="'.$row[3].'" width="180" height="100" border="0"/></a>'; ?>
asi continuo molestando , pero no pille ni un codigo para esto me tenia indignado , ahora tu me das un poco de hope , jejejeweno amigo seguimos = te muestro como esta el codigo y como lo recepciono, es algo asi :
<head>
<script language="JavaScript" type="text/javascript">
<!--
function PopWindow(laurl)
{
window.open(laurl,'detalle','width=450,height=390,menubar=no,scrollbars=no,toolbar=no,location=yes,directories=no,resizable=no,top=200,left=350');
}
//-->
</script>
</head>
<body>
echo"<table width='39%' border='0' cellspacing='0' cellpadding='0'>
<tr>
<td width='61%' rowspan='2' align='left' valign='middle'>
<div align='center'><font color='#FFFF00' size='3'></font></div>
<div align='left'><font color='#FFFFFF' size='1' face='Verdana, Arial, Helvetica, sans-serif'><strong>$row[2]</strong></font></div></td>
<td align='center' valign='middle'><font color='#FFFF00' size='4'><strong>$row[1]</strong></font></td>
</tr>
<tr>
<td width='39%' height='106'><a href='javascriptopWindow(\'popdetalle.php?var=\'+'.$row[1].'+\'&var2=\'+'.$row[2].')'><<img src='$row[3]' width='180' height='100' border='0'/></a></td>
</tr>
<tr>
<td height='3' colspan='2' align='center' valign='top'><img src='imagenes/linea_base_ventas.jpg' width='410' height='2' /></td>
</tr>
</table>";
</body>
como veras aparentemente esta bien , pero ni siquiera abre la popup me tira un error de pagina en la barra de estado , y no hay manera de enviar solo las variables y despues concatenarlas en javascript en la o las variables laurl y laurl2
basicamente como en el primer script que me mostraste :
<a href="javascriptopWindow($row[0], $row[1])">
<script language="JavaScript" type="text/javascript">
<!--
function PopWindow(laurl, laurl2)
{
laurl='popdetalle.php?var='+laurl+'&var2='+laurl2
window.open('popdetalle.php?var='+laurl+',detalle','width=400,height=300,menubar=no,scrollbars=no,toolbar=no,location=yes,directories=no,resizable=no,top=200,left=350');
}
//-->
</script>
creo yo que puede ser , que opinas tu ,????
<html>
<head>
<script language="JavaScript" type="text/javascript">
<!--
function PopWindow(laurl){
alert(laurl);
window.open(laurl,'detalle','width=450,height=390, menubar=no,scrollbars=no,toolbar=no,location=yes,d irectories=no,resizable=no,top=200,left=350');
}
//-->
</script>
</head>
<body>
<?php
$row[1]=1;
$row[2]=2;
$row[3]=3;
echo "<table width='39%' border='0' cellspacing='0' cellpadding='0'>
<tr>
<td width='61%' rowspan='2' align='left' valign='middle'>
<div align='center'><font color='#FFFF00' size='3'></font></div>
<div align='left'><font color='#FFFFFF' size='1' face='Verdana, Arial, Helvetica, sans-serif'><strong>$row[2]</strong></font></div></td>
<td align='center' valign='middle'><font color='#FFFF00' size='4'><strong>$row[1]</strong></font></td>
</tr>
<tr>
<td width='39%' height='106'><a href='javascript:PopWindow(\"popdetalle.php?var=$row[1]&var2=$row[2]\")'><img src='$row[3]' width='180' height='100' border='0'/></a></td>
</tr>
<tr>
<td height='3' colspan='2' align='center' valign='top'><img src='imagenes/linea_base_ventas.jpg' width='410' height='2' /></td>
</tr>
</table>
";
?>
</body>
</html>