从PHP调用mysql存储过程的问题 [英] Problem with calling mysql stored procedure from PHP

查看:81
本文介绍了从PHP调用mysql存储过程的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友

i我遇到了mysql存储过程的问题,我试图从php调用程序,但我只是得到错误...任何帮助将不胜感激..下面是我的代码和我得到的错误



我在创建程序时的代码

hi friends
i am having a problem with mysql stored procedure, am trying to call procedure from php but i only get errors... any help will be greatly appreciated.. below is my code and errors am getting

CODE I UDE IN CREATING PROCEDURE

DELIMITER //
CREATE PROCEDURE TrackAlbumAndArtist (IN TheAlbumID INT(11), IN TheCategory VARCHAR(50))

BEGIN

SELECT `upload2`.`id`, `upload2`.`name` ,  `upload2`.`type` ,  `upload2`.`size` ,  `upload2`.`path` ,  `upload2`.`category` ,  `upload2`.`description` ,  `upload2`.`number_of_downloads` , `upload2`. `Title` , `upload2`. `artist_icon` , `upload2`. `Votes` , `upload2`. `albumID` ,  `upload2`.`date` ,  `upload2`.`artist_id`, `albums`.`id` ,`albums`.`album_name`,`albums`.`date_realeased`,`albums`.`artistID`,`albums`.`total_songs_in_album` ,`albums`.`description`,`albums`.`artwork` ,  `artists`.`id` , `artists`.`name` ,  `artists`.`country` ,  `artists`.`music_type` ,  `artists`.`birth_day` ,  `artists`.`spouse_name` ,  `artists`.`started_singing_since` ,  `artists`.`sex` ,  `artists`.`brief_description` , `artists`.`stage_name` , `artists`.`marital_status` ,  `artists`.`aka` ,  `artists`.`image`FROM `upload2`

 INNER JOIN `albums` ON `upload2`.`albumID` = `albums`.`id`
 INNER JOIN `artists` ON `albums`.`artistID` = `artists`.`id`
   where `upload2`.`category` = TheCategory   and  `upload2`. `albumID` = TheAlbumID ORDER BY `upload2`.`id` DESC;

END







它成功创建了程序..



代码调用存储过程

.......... ...............










it create the procedure succesfully..

CODE TO CALL STORED PROCEDURE
........................



<?php
include('/includes/scConfig.php');

$page = (int) (!isset($_GET['p'])) ? 1 : $_GET['p'];
# sql query
$thealbumID ='3';
$MusicCategory ='Audios';


$tr = mysql_query("call TrackAlbumAndArtist('".$thealbumID."','".$MusicCategory."')", $db);
$sql = "call TrackAlbumAndArtist('".$thealbumID."','".$MusicCategory."')";
   
# find out query stat point
$start = ($page * $limit) - $limit;
# query for page navigation
if( mysql_num_rows(mysql_query ($sql)) > ($page * $limit) ){
	$next = ++$page;
}
$query = mysql_query($sql . " LIMIT {$start}, {$limit}");
if (mysql_num_rows($query) < 1) {
	header('HTTP/1.0 404 Not Found');
	echo 'oops.. Page not found!';
	exit();
}
?>





my scConfig文件





my scConfig File

<?php
/**
 * DB Configuration
 */
define('DB_HOST',			'localhost');
define('DB_USER',			'west');
define('DB_PASS',			'west@53');
define('DB_NAME',			'westMusic');
$limit = 10; #item per page
# db connect
$link = mysql_connect(DB_HOST, DB_USER, DB_PASS) or die('Could not connect to MySQL DB ') . mysql_error();
$db = mysql_select_db(DB_NAME, $link); 

?>





什么是当我执行它时我做错了它给了我这些错误



警告:mysql_query()期望参数2是资源,在C:\ xampp \中给出布尔值第10行的htdocs \53Africa \ music.php



警告:mysql_num_rows()期望参数1为资源,布尔值在C:\ xampp \中给出第16行的htdocs \53Africa \ music.php



警告:mysql_num_rows()期望参数1为资源,在C:\ xampp \中给出布尔值第20行的htdocs\53Africa \ musicic.php

oops ..找不到页面!





我在这里做错了吗....

提前谢谢



what am i doing wrong when i execute it it gives me these errors

Warning: mysql_query() expects parameter 2 to be resource, boolean given in C:\xampp\htdocs\53Africa\music.php on line 10

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\53Africa\music.php on line 16

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\53Africa\music.php on line 20
oops.. Page not found!


please am i doing something wrong here....
Thanks in advance

推荐答案

page =(int)( !isset(
page = (int) (!isset(


_GET [' p'])) ? 1
_GET['p'])) ? 1 :


_GET [' p'];
#sql查询
_GET['p']; # sql query


这篇关于从PHP调用mysql存储过程的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆