Click here to Skip to main content
15,909,205 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
SQL
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
<?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 File

PHP
<?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); 

?>


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
Posted
Comments
Richard Deeming 22-Sep-15 13:54pm    
Your code is vulnerable to SQL Injection[^].

NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query.

Also, the mysql_* functions have been deprecated, and should not be used.

Moving from mysql_query to PDO[^]
Query Parameterization Cheat Sheet | OWASP[^]
Mohibur Rashid 23-Sep-15 20:26pm    
mysql_* functions do not have option to call stored procedure. better to move to mysqli_* functions. read the php page
Ese Ochuko 28-Sep-15 18:17pm    
Thanks alot for your reply, helped me alot. thanks again

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900